diff --git a/src/esxport.py b/src/esxport.py index 1534aa6..2e147cf 100644 --- a/src/esxport.py +++ b/src/esxport.py @@ -185,7 +185,8 @@ def _clean_scroll_ids(self: Self) -> None: def _extract_headers(self: Self) -> list[str]: """Extract CSV headers from the first line of the file.""" - with Path(f"{self.opts.output_file}.tmp").open() as f: + file_name = f"{self.opts.output_file}.tmp" + with Path(file_name).open() as f: first_line = json.loads(f.readline().strip("\n")) return list(first_line.keys()) diff --git a/test/click/cli_test.py b/test/click/cli_test.py index 18c9fed..38f4848 100644 --- a/test/click/cli_test.py +++ b/test/click/cli_test.py @@ -116,6 +116,7 @@ def test_query_accepts_dict(self: Self, cli_runner: CliRunner, esxport_obj_with_ catch_exceptions=False, ) assert result.exit_code == 0 + TestExport.rm_csv_export_file(esxport_obj_with_data.opts.output_file) def test_error_is_rasied_on_invalid_json(self: Self, cli_runner: CliRunner) -> None: """Test sort input is in the form field:sort_order.""" diff --git a/test/esxport/_export_test.py b/test/esxport/_export_test.py index b715c61..56e1ffd 100644 --- a/test/esxport/_export_test.py +++ b/test/esxport/_export_test.py @@ -60,10 +60,11 @@ def test_headers_extraction( """Check if exception is raised when formatting is invalid.""" esxport_obj.opts.output_file = f"{inspect.stack()[0].function}.csv" test_json = {"age": 2, "bar": "foo", "hello": "world"} - with Path(f"{esxport_obj.opts.output_file}.tmp").open(mode="w", encoding="utf-8") as tmp_file: + temp_file = f"{esxport_obj.opts.output_file}.tmp" + with Path(temp_file).open("w") as tmp_file: tmp_file.write(json.dumps(test_json)) tmp_file.write("\n") - assert Path(f"{esxport_obj.opts.output_file}.tmp").exists() is True + assert Path(temp_file).exists() is True keys = list(test_json.keys()) assert esxport_obj._extract_headers() == keys TestExport.rm_export_file(f"{inspect.stack()[0].function}.csv")