-
Notifications
You must be signed in to change notification settings - Fork 57
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
trying to fix-Init should refuse if there are existing results #560
base: master
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 |
---|---|---|
|
@@ -5,14 +5,16 @@ | |
import stat | ||
|
||
import pytest | ||
|
||
from exit_codes import ExitCode | ||
|
||
import cosmic_ray.cli | ||
import cosmic_ray.config | ||
import cosmic_ray.modules | ||
import cosmic_ray.mutating | ||
import cosmic_ray.plugins | ||
|
||
from cosmic_ray.work_db import WorkDB | ||
from cosmic_ray.work_item import WorkItem,MutationSpec | ||
|
||
@pytest.fixture | ||
def config_file(tmpdir): | ||
|
@@ -64,6 +66,56 @@ def test_non_existent_config_file_returns_EX_NOINPUT(session, local_unittest_con | |
assert cosmic_ray.cli.main(["exec", "no-such-file", str(session)]) == ExitCode.CONFIG | ||
|
||
|
||
|
||
def test_init_with_existing_results_no_force(session, local_unittest_config): | ||
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. You'll probably need to use the |
||
"""Test that init exits without reinitializing when results exist and force=False""" | ||
# Sample WorkItem creation | ||
mutation_spec = MutationSpec( | ||
module_path="src/example/test.py", | ||
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. Pass a |
||
operator_name="delete_line", | ||
occurrence=1, | ||
start_pos=(10, 0), | ||
end_pos=(10, 20), | ||
operator_args={"comment": "Delete print statement"} | ||
) | ||
|
||
work_items = [ | ||
WorkItem( | ||
job_id="test_job_123", | ||
mutations=(mutation_spec,) | ||
) | ||
] | ||
|
||
db=WorkDB(session,1) | ||
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. Use Also, it would be more idiomatic to use the |
||
db.add_work_items(work_items) | ||
|
||
# Verify initial database state has our test work items | ||
initial_count = db.num_work_items | ||
assert initial_count == len(work_items) | ||
|
||
|
||
|
||
result = cosmic_ray.cli.main(["init", local_unittest_config, str(session)]) | ||
db=WorkDB(session,2) | ||
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. Use |
||
final_count = db.num_results | ||
assert final_count == initial_count # Confirm work items are unchanged | ||
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. You seem to be comparing the wrong things here. |
||
assert result == ExitCode.OK | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
def test_init_with_existing_results_force(session, local_unittest_config,force): | ||
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. As mentioned earlier, you don't need (and aren't really using) the |
||
"""Test that reinitialization occurs when force=True""" | ||
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. This isn't testing what it claims to test. You're not re-initializing the database, just initializing it, so passing
|
||
|
||
result = cosmic_ray.cli.main(["init", local_unittest_config, str(session),"--force"]) | ||
assert result == ExitCode.OK | ||
|
||
@pytest.mark.skip("need to sort this API out") | ||
def test_unreadable_file_returns_EX_PERM(tmpdir, local_unittest_config): | ||
p = tmpdir.ensure("bogus.session.sqlite") | ||
|
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.
This fixture doesn't seem to be doing anything. It should be removed.