Skip to content

Commit

Permalink
✅ Updated json writer
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbadyal committed Sep 25, 2023
1 parent 9ba6285 commit 7230acf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion esxport/esxport.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _extract_headers(self: Self) -> list[str]:
"""Extract CSV headers from the first line of the file."""
file_name = f"{self.opts.output_file}.tmp"
with Path(file_name).open() as f:
first_line = json.loads(f.readline().strip("\n"))
first_line = json.loads(f.readline())
return list(first_line.keys())

def _export(self: Self) -> None:
Expand Down
7 changes: 2 additions & 5 deletions test/esxport/_export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def test_headers_extraction(
test_json = {"age": 2, "bar": "foo", "hello": "world"}
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(temp_file).exists() is True
keys = list(test_json.keys())
assert esxport_obj._extract_headers() == keys
json.dump(test_json, tmp_file)
assert esxport_obj._extract_headers() == list(test_json.keys())
TestExport.rm_export_file(f"{inspect.stack()[0].function}.csv")

0 comments on commit 7230acf

Please sign in to comment.