bpo-29623: Make PathLike objects work with ConfigParser.read() (#242)

This commit is contained in:
David Ellis 2017-03-03 17:14:27 +00:00 committed by Berker Peksag
parent 677ab995ce
commit 85b8d01c91
4 changed files with 31 additions and 8 deletions

View file

@ -2,6 +2,7 @@ import collections
import configparser
import io
import os
import pathlib
import textwrap
import unittest
import warnings
@ -720,6 +721,16 @@ boolean {0[0]} NO
parsed_files = cf.read(file1)
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only a Path object:
cf = self.newconfig()
parsed_files = cf.read(pathlib.Path(file1))
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we passed both a filename and a Path object:
cf = self.newconfig()
parsed_files = cf.read([pathlib.Path(file1), file1])
self.assertEqual(parsed_files, [file1, file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only missing files:
cf = self.newconfig()
parsed_files = cf.read(["nonexistent-file"])