From bdb8c8771f01b34e9e0cce1462d81ba99328e205 Mon Sep 17 00:00:00 2001 From: dllliu Date: Tue, 21 May 2024 15:53:53 -0600 Subject: [PATCH 1/2] fix tests for windows --- tests/unit/dataclasses/test_template_generation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/dataclasses/test_template_generation.py b/tests/unit/dataclasses/test_template_generation.py index b057274a1..2bf9b3c8a 100644 --- a/tests/unit/dataclasses/test_template_generation.py +++ b/tests/unit/dataclasses/test_template_generation.py @@ -65,11 +65,11 @@ def test_template_generation_inmemory( template = template.inline_dependencies() bindings, filled = template.fill(BLDG, include_optional=include_optional) - with NamedTemporaryFile(suffix=".xlsx") as dest: + with NamedTemporaryFile(suffix=".xlsx", delete=False) as dest: output = template.generate_spreadsheet() assert output is not None dest.write(output.getbuffer()) - + dest.flush() w = openpyxl.load_workbook(dest.name) _add_spreadsheet_row(w.active, bindings) w.save(Path(dest.name)) @@ -92,10 +92,10 @@ def test_template_generation_file( template = template.inline_dependencies() bindings, filled = template.fill(BLDG, include_optional=include_optional) - with NamedTemporaryFile(suffix=".xlsx") as dest: + with NamedTemporaryFile(suffix=".xlsx", delete=False) as dest: output = template.generate_spreadsheet(Path(dest.name)) assert output is None - + dest.flush() w = openpyxl.load_workbook(dest.name) _add_spreadsheet_row(w.active, bindings) w.save(Path(dest.name)) @@ -118,7 +118,7 @@ def test_csv_generation_inmemory( template = template.inline_dependencies() bindings, filled = template.fill(BLDG, include_optional=include_optional) - with NamedTemporaryFile(mode="w", suffix=".csv") as dest: + with NamedTemporaryFile(mode="w", suffix=".csv", delete=False) as dest: output = template.generate_csv() assert output is not None dest.writelines([output.getvalue()]) @@ -145,7 +145,7 @@ def test_csv_generation_file( template = template.inline_dependencies() bindings, filled = template.fill(BLDG, include_optional=include_optional) - with NamedTemporaryFile(mode="w", suffix=".csv") as dest: + with NamedTemporaryFile(mode="w", suffix=".csv", delete=False) as dest: output = template.generate_csv(Path(dest.name)) assert output is None From 44d9a821cee7e750569b1895bf9d5c97e2c4b9fe Mon Sep 17 00:00:00 2001 From: daniel <78173152+dllliu@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:24:01 +0000 Subject: [PATCH 2/2] flush buffer in tests --- tests/unit/dataclasses/test_template_generation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/dataclasses/test_template_generation.py b/tests/unit/dataclasses/test_template_generation.py index 2bf9b3c8a..7a5715fc4 100644 --- a/tests/unit/dataclasses/test_template_generation.py +++ b/tests/unit/dataclasses/test_template_generation.py @@ -148,6 +148,7 @@ def test_csv_generation_file( with NamedTemporaryFile(mode="w", suffix=".csv", delete=False) as dest: output = template.generate_csv(Path(dest.name)) assert output is None + dest.flush() with open(Path(dest.name)) as f: params = f.read().strip().split(",")