From dea2669de214e643d5476b5ea2648bd8724d6e09 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 16 Jul 2025 14:33:10 +0200 Subject: [PATCH] Solved unclosed file <_io.TextIOWrapper warnings --- .dockerignore | 4 ++++ tests/unit/cli/create/test_role.py | 6 ++++-- tests/unit/cli/fix/test_vars_main_files.py | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index d45eb263..207d8953 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,7 @@ +# The .gitignore is the single point of truth for files which should be ignored. +# Add patterns, files and folders to the .gitignore and execute 'make build' +# NEVER TOUCH THE .dockerignore, BECAUSE IT ANYHOW WILL BE OVERWRITTEN + site.retry *__pycache__ venv diff --git a/tests/unit/cli/create/test_role.py b/tests/unit/cli/create/test_role.py index 0509ed89..8bd00edc 100644 --- a/tests/unit/cli/create/test_role.py +++ b/tests/unit/cli/create/test_role.py @@ -88,7 +88,8 @@ class TestCreateDockerRoleCLI(unittest.TestCase): data['ports']['localhost']['http']['app2'] = 8001 dump_yaml_with_comments(data, self.ports_file) # Check comment and new entry - text = open(self.ports_file).read() + with open(self.ports_file) as f: + text = f.read() self.assertIn('# existing port', text) self.assertIn('app2: 8001', text) @@ -128,7 +129,8 @@ class TestCreateDockerRoleCLI(unittest.TestCase): f.write('Line1\n') builtins.input = lambda _: '3' render_templates(src, dst, {}) - content = open(out_file).read().splitlines() + with open(out_file) as f: + content = f.read().splitlines() self.assertIn('Line1', content) self.assertIn('Line2', content) builtins.input = original_input diff --git a/tests/unit/cli/fix/test_vars_main_files.py b/tests/unit/cli/fix/test_vars_main_files.py index 30c0f112..8760a54d 100644 --- a/tests/unit/cli/fix/test_vars_main_files.py +++ b/tests/unit/cli/fix/test_vars_main_files.py @@ -49,7 +49,8 @@ class TestEnsureVarsMain(unittest.TestCase): vm = os.path.join(role, "vars", "main.yml") self.assertTrue(os.path.exists(vm)) - data = yaml.safe_load(open(vm)) + with open(vm) as f: + data = yaml.safe_load(f) # Expect application_id: 'foobar' self.assertEqual(data.get("application_id"), "foobar") @@ -61,7 +62,8 @@ class TestEnsureVarsMain(unittest.TestCase): run(prefix="desk-", preview=False, overwrite=True) path = os.path.join(role, "vars", "main.yml") - data = yaml.safe_load(open(path)) + with open(path) as f: + data = yaml.safe_load(f) # application_id must be corrected... self.assertEqual(data.get("application_id"), "baz")