Skip to content

Commit

Permalink
🔥 Use variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbadyal committed Sep 23, 2023
1 parent 379f21a commit bdf00cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/esxport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions test/click/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 3 additions & 2 deletions test/esxport/_export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit bdf00cf

Please sign in to comment.