-
Notifications
You must be signed in to change notification settings - Fork 6
Add logs_size to con-duct ls output
#406
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
6cb3bfb
57ddd55
19ecc38
ca997ba
c19eaf9
37c199c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| MINIMUM_SCHEMA_VERSION, | ||
| _flatten_dict, | ||
| _restrict_row, | ||
| compute_files_size, | ||
| ensure_compliant_schema, | ||
| load_duct_runs, | ||
| ls, | ||
|
|
@@ -164,6 +165,49 @@ def side_effect(filename: str) -> Any: | |
| assert "Skipping empty file" in caplog.text | ||
|
|
||
|
|
||
| def test_compute_files_size_sums_all_files() -> None: | ||
| """Test that compute_files_size sums sizes of all files with the given prefix.""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| prefix = os.path.join(tmpdir, "run_") | ||
| # Use arbitrary suffixes; compute_files_size globs all files with the prefix | ||
| for suffix, content in [("a", b"hello"), ("b", b"world!"), ("c", b"{}...")]: | ||
| with open(f"{prefix}{suffix}", "wb") as f: | ||
| f.write(content) | ||
| expected = sum(len(c) for c in [b"hello", b"world!", b"{}..."]) | ||
| assert compute_files_size(prefix) == expected | ||
|
|
||
|
|
||
| def test_compute_files_size_empty_prefix() -> None: | ||
| """Test that compute_files_size returns 0 when no files match the prefix.""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| prefix = os.path.join(tmpdir, "nonexistent_") | ||
| assert compute_files_size(prefix) == 0 | ||
|
|
||
|
|
||
| def test_load_duct_runs_includes_files_size() -> None: | ||
| """Test that load_duct_runs populates files_size for each run.""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| prefix = os.path.join(tmpdir, "run_") | ||
| info_path = f"{prefix}info.json" | ||
| with open(info_path, "w") as f: | ||
| json.dump( | ||
| { | ||
| "schema_version": MINIMUM_SCHEMA_VERSION, | ||
| "prefix": prefix, | ||
| "execution_summary": {}, | ||
| "message": "", | ||
| }, | ||
| f, | ||
| ) | ||
| # Create a sibling file to count toward files_size | ||
| with open(f"{prefix}stdout", "w") as f: | ||
| f.write("some output") | ||
| result = load_duct_runs([info_path]) | ||
| assert len(result) == 1 | ||
| assert "files_size" in result[0] | ||
| assert result[0]["files_size"] > 0 | ||
|
|
||
|
|
||
| class TestLS(unittest.TestCase): | ||
| def setUp(self) -> None: | ||
| """Create a temporary directory and test files.""" | ||
|
|
@@ -389,3 +433,35 @@ def test_ls_reverse(self) -> None: | |
| prefixes_reversed = [row["prefix"] for row in parsed_reversed] | ||
|
|
||
| assert prefixes_reversed == list(reversed(prefixes_normal)) | ||
|
|
||
| def test_ls_files_size_in_output(self) -> None: | ||
| """Test that files_size field appears in ls output and is humanized.""" | ||
| args = argparse.Namespace( | ||
| paths=[os.path.join(self.temp_dir.name, "file1_info.json")], | ||
| colors=False, | ||
| fields=["files_size"], | ||
| eval_filter=None, | ||
| format="json", | ||
| func=ls, | ||
| reverse=False, | ||
| ) | ||
| result = self._run_ls(["file1_info.json"], "json", args) | ||
| parsed = json.loads(result) | ||
| assert len(parsed) == 1 | ||
| assert "files_size" in parsed[0] | ||
|
|
||
| def test_ls_files_size_humanized_in_summaries(self) -> None: | ||
| """Test that files_size is humanized in summaries output.""" | ||
| args = argparse.Namespace( | ||
| paths=[os.path.join(self.temp_dir.name, "file1_info.json")], | ||
| colors=False, | ||
| fields=["files_size"], | ||
| eval_filter=None, | ||
| format="summaries", | ||
| func=ls, | ||
| reverse=False, | ||
| ) | ||
| result = self._run_ls(["file1_info.json"], "summaries", args) | ||
| assert "Files Size:" in result | ||
| # Should show humanized size (Bytes or kB etc.) not raw integer | ||
| assert any(unit in result for unit in ["Byte", "kB", "MB", "GB"]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think some of those tests warrant just addition of testing within existing tests instead of breeding their own -- I bet we do not have a test per each column. @copilot please review and adjust to retain coverage and testing but reduce code added in the tests
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidated in ca997ba:
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warrants at least logging for debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot add logging ... since unexpected, I think it could even be WARNING
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
lgr.debug("Could not get size of %s: %s", path_str, e)in theexcept OSErrorblock in ca997ba.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgraded to
lgr.warning(...)in c19eaf9.