-
Notifications
You must be signed in to change notification settings - Fork 0
π§ͺ Add testing foundation for main.py #3
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 all commits
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 |
|---|---|---|
| @@ -1,0 +1,34 @@ | ||
| import argparse | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| def parse_args(args): | ||
| parser = argparse.ArgumentParser(description="Multi-Modal Evidence Review System") | ||
| parser.add_argument("--input", type=str, default="dataset/claims.csv", help="Path to input claims CSV file") | ||
| parser.add_argument("--output", type=str, default="output.csv", help="Path to output CSV file") | ||
| parser.add_argument("--sample", action="store_true", help="Run on sample_claims.csv instead") | ||
| return parser.parse_args(args) | ||
|
|
||
| def main(args=None): | ||
| if args is None: | ||
| args = sys.argv[1:] | ||
|
|
||
| try: | ||
| parsed_args = parse_args(args) | ||
| except SystemExit as e: | ||
|
Check failure on line 18 in code/main.py
|
||
| return e.code | ||
|
|
||
| input_file = "dataset/sample_claims.csv" if parsed_args.sample else parsed_args.input | ||
| output_file = parsed_args.output | ||
|
|
||
| print(f"Starting evidence review pipeline...") | ||
|
Check warning on line 24 in code/main.py
|
||
| print(f"Input: {input_file}") | ||
| print(f"Output: {output_file}") | ||
|
|
||
| # TODO: Initialize and run the pipeline | ||
|
Check warning on line 28 in code/main.py
|
||
|
|
||
| print("Pipeline completed successfully.") | ||
| return 0 | ||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||||||||||||||
| import pytest | ||||||||||||||||||
| import sys | ||||||||||||||||||
| from main import parse_args, main | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_parse_args_defaults(): | ||||||||||||||||||
| args = parse_args([]) | ||||||||||||||||||
| assert args.input == "dataset/claims.csv" | ||||||||||||||||||
| assert args.output == "output.csv" | ||||||||||||||||||
| assert args.sample is False | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_parse_args_custom_files(): | ||||||||||||||||||
| args = parse_args(["--input", "custom_in.csv", "--output", "custom_out.csv"]) | ||||||||||||||||||
| assert args.input == "custom_in.csv" | ||||||||||||||||||
| assert args.output == "custom_out.csv" | ||||||||||||||||||
| assert args.sample is False | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_parse_args_sample_flag(): | ||||||||||||||||||
| args = parse_args(["--sample"]) | ||||||||||||||||||
| assert args.sample is True | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_parse_args_help(capsys): | ||||||||||||||||||
| with pytest.raises(SystemExit) as excinfo: | ||||||||||||||||||
| parse_args(["--help"]) | ||||||||||||||||||
| assert excinfo.value.code == 0 | ||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||
| assert "Multi-Modal Evidence Review System" in captured.out | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_parse_args_invalid_argument(capsys): | ||||||||||||||||||
| with pytest.raises(SystemExit) as excinfo: | ||||||||||||||||||
| parse_args(["--invalid-flag"]) | ||||||||||||||||||
| assert excinfo.value.code == 2 | ||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||
| assert "unrecognized arguments: --invalid-flag" in captured.err | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_main_execution_defaults(capsys): | ||||||||||||||||||
| exit_code = main([]) | ||||||||||||||||||
| assert exit_code == 0 | ||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||
| assert "Starting evidence review pipeline" in captured.out | ||||||||||||||||||
| assert "Input: dataset/claims.csv" in captured.out | ||||||||||||||||||
| assert "Output: output.csv" in captured.out | ||||||||||||||||||
|
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. suggestion (testing): Consider asserting that the final success message is printed to ensure the whole happy-path is exercised. Since assert "Pipeline completed successfully." in captured.out |
||||||||||||||||||
|
|
||||||||||||||||||
| def test_main_execution_sample_flag(capsys): | ||||||||||||||||||
| exit_code = main(["--sample"]) | ||||||||||||||||||
| assert exit_code == 0 | ||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||
| assert "Input: dataset/sample_claims.csv" in captured.out | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_main_execution_custom_args(capsys): | ||||||||||||||||||
| exit_code = main(["--input", "test_in.csv", "--output", "test_out.csv"]) | ||||||||||||||||||
| assert exit_code == 0 | ||||||||||||||||||
| captured = capsys.readouterr() | ||||||||||||||||||
| assert "Input: test_in.csv" in captured.out | ||||||||||||||||||
| assert "Output: test_out.csv" in captured.out | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_main_help_returns_zero(capsys): | ||||||||||||||||||
|
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. Drop unused These trigger Ruff Proposed fix-def test_main_help_returns_zero(capsys):
+def test_main_help_returns_zero():
@@
-def test_main_invalid_args_returns_error(capsys):
+def test_main_invalid_args_returns_error():Also applies to: 60-60 π§° Toolsπͺ Ruff (0.15.17)[warning] 56-56: Unused function argument: (ARG001) π€ Prompt for AI AgentsSource: Linters/SAST tools |
||||||||||||||||||
| exit_code = main(["--help"]) | ||||||||||||||||||
| assert exit_code == 0 | ||||||||||||||||||
|
Comment on lines
+56
to
+58
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. suggestion (testing): Also assert that the help text is printed in Since def test_main_help_returns_zero(capsys):
exit_code = main(["--help"])
assert exit_code == 0
captured = capsys.readouterr()
assert "Multi-Modal Evidence Review System" in captured.outThis verifies the help content from the main entry point, not just the exit code.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_main_invalid_args_returns_error(capsys): | ||||||||||||||||||
| exit_code = main(["--invalid"]) | ||||||||||||||||||
| assert exit_code == 2 | ||||||||||||||||||
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.
Remove unnecessary f-string prefix on static text.
This triggers Ruff
F541and can fail lint checks; use a normal string literal.Proposed fix
π Committable suggestion
π§° Tools
πͺ GitHub Check: SonarCloud Code Analysis
[warning] 24-24: Add replacement fields or use a normal string instead of an f-string.
See more on https://sonarcloud.io/project/issues?id=NITISH-R-G_hackerrank-orchestrate-june26&issues=AZ7fBx94jTJXDMZfJPhY&open=AZ7fBx94jTJXDMZfJPhY&pullRequest=3
πͺ Ruff (0.15.17)
[error] 24-24: f-string without any placeholders
Remove extraneous
fprefix(F541)
π€ Prompt for AI Agents
Source: Linters/SAST tools