Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Use variable names #37

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")