consistent 'with open(…) as fp:' syntax

This commit is contained in:
Mike Fährmann
2024-06-14 01:22:00 +02:00
parent 3fc2e61818
commit 9c65db2a92
15 changed files with 46 additions and 46 deletions

View File

@@ -165,12 +165,12 @@ class TestConfig(unittest.TestCase):
def test_load(self):
with tempfile.TemporaryDirectory() as base:
path1 = os.path.join(base, "cfg1")
with open(path1, "w") as file:
file.write('{"a": 1, "b": {"a": 2, "c": "text"}}')
with open(path1, "w") as fp:
fp.write('{"a": 1, "b": {"a": 2, "c": "text"}}')
path2 = os.path.join(base, "cfg2")
with open(path2, "w") as file:
file.write('{"a": 7, "b": {"a": 8, "e": "foo"}}')
with open(path2, "w") as fp:
fp.write('{"a": 7, "b": {"a": 8, "e": "foo"}}')
config.clear()
config.load((path1,))
@@ -208,8 +208,8 @@ class TestConfigFiles(unittest.TestCase):
def _load(name):
path = os.path.join(ROOTDIR, "docs", name)
try:
with open(path) as file:
return util.json_loads(file.read())
with open(path) as fp:
return util.json_loads(fp.read())
except FileNotFoundError:
raise unittest.SkipTest(path + " not available")

View File

@@ -28,14 +28,14 @@ class TestCookiejar(unittest.TestCase):
cls.path = tempfile.TemporaryDirectory()
cls.cookiefile = join(cls.path.name, "cookies.txt")
with open(cls.cookiefile, "w") as file:
file.write("""# HTTP Cookie File
with open(cls.cookiefile, "w") as fp:
fp.write("""# HTTP Cookie File
.example.org\tTRUE\t/\tFALSE\t253402210800\tNAME\tVALUE
""")
cls.invalid_cookiefile = join(cls.path.name, "invalid.txt")
with open(cls.invalid_cookiefile, "w") as file:
file.write("""# asd
with open(cls.invalid_cookiefile, "w") as fp:
fp.write("""# asd
.example.org\tTRUE/FALSE\t253402210800\tNAME\tVALUE
""")

View File

@@ -136,8 +136,8 @@ class TestDownloaderBase(unittest.TestCase):
if content:
mode = "w" + ("b" if isinstance(content, bytes) else "")
with pathfmt.open(mode) as file:
file.write(content)
with pathfmt.open(mode) as fp:
fp.write(content)
return pathfmt
@@ -151,8 +151,8 @@ class TestDownloaderBase(unittest.TestCase):
# test content
mode = "r" + ("b" if isinstance(output, bytes) else "")
with pathfmt.open(mode) as file:
content = file.read()
with pathfmt.open(mode) as fp:
content = fp.read()
self.assertEqual(content, output)
# test filename extension