-
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?
Conversation
src/cosmic_ray/cli.py
Outdated
@@ -96,7 +97,11 @@ def init(config_file, session_file): | |||
log.info(" - %s: %s", directory, ", ".join(sorted(files))) | |||
|
|||
with use_db(session_file) as database: | |||
cosmic_ray.commands.init(modules, database, operators_cfg) | |||
if database.num_results>0: |
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.
I think this logic is incorrect. If database.num_results
is greater than zero, it will always exit, event if force
is True
. What we want is for initialization to occur if force
is True
, no matter what the state of the existing database is.
Ok will try
…On Mon, 28 Oct, 2024, 13:01 Austin Bingham, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/cosmic_ray/cli.py
<#560 (comment)>
:
> @@ -96,7 +97,11 @@ def init(config_file, session_file):
log.info(" - %s: %s", directory, ", ".join(sorted(files)))
with use_db(session_file) as database:
- cosmic_ray.commands.init(modules, database, operators_cfg)
+ if database.num_results>0:
I think this logic is incorrect. If database.num_results is greater than
zero, it will always exit, event if force is True. What we want is for
initialization to occur if force is True, no matter what the state of the
existing database is.
—
Reply to this email directly, view it on GitHub
<#560 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A6BG3WUQYV6IVZPX2NJOPETZ5XK2PAVCNFSM6AAAAABQWYLI52VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGOJYGE2DMMZWGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@@ -59,11 +60,24 @@ def test_non_existent_session_file_returns_EX_NOINPUT(local_unittest_config): | |||
assert cosmic_ray.cli.main(["exec", str(local_unittest_config), "foo.session"]) == ExitCode.NO_INPUT | |||
|
|||
|
|||
def test_non_existent_config_file_returns_EX_NOINPUT(session, local_unittest_config): | |||
cosmic_ray.cli.main(["init", local_unittest_config, str(session)]) | |||
def test_non_existent_config_file_returns_EX_NOINPUT(session, local_unittest_config,force): |
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 test (and all tests which take a force
parameter) don't work because you don't have a fixture providing the value for force
. In all cases, I don't think the tests actually need to use a fixture for force
. You can simply pass the correct value - True
or False
- into cosmic_ray.cli.main
.
def test_init_with_existing_results_no_force(session, local_unittest_config,force): | ||
"""Test that init exits without reinitializing when results exist and force=False""" | ||
with use_db(session) as database: | ||
database.num_results = 1 # Simulate existing results |
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.
You can't just set num_results
like this. The WorkDB
class won't allow it.
You clearly haven't run these tests because none of them run. Please don't resubmit until the tests actually run.
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.
sorry i commited the wrong branch will fix the changes
hi @abingham for the case when force is false what will the test case reflect is creating a mockdb the right kind of approach??? |
@abingham ??? |
A test for the |
ok will do |
hi @abingham both the tests are still failing can u pls check them once and guide me to the necessary steps so that i can fix my mistake i cant seem to figure it out |
@@ -2,7 +2,9 @@ | |||
|
|||
import pytest | |||
|
|||
|
|||
@pytest.fixture |
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.
"""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 comment
The reason will be displayed to describe this comment to others. Learn more.
Pass a Path
object here, not a string. I know that MutationSpec
will convert it, but I'd like to get away from depending on that.
) | ||
] | ||
|
||
db=WorkDB(session,1) |
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.
Use WorkDB.Mode.create
here instead of just 1
.
Also, it would be more idiomatic to use the use_db
context manager rather than opening the WorkDB directly like this.
|
||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Use WorkDB.Mode.open
here, not just 2
. And use use_db
.
|
||
|
||
|
||
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 comment
The 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 force
fixture here. Remove it.
|
||
|
||
def test_init_with_existing_results_force(session, local_unittest_config,force): | ||
"""Test that reinitialization occurs when force=True""" |
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 isn't testing what it claims to test. You're not re-initializing the database, just initializing it, so passing --force
doesn't do anything special in this case. You need to:
- Create the WorkDB
- Put some results into it and verify that it has the results
- Re-initialize it with
--force
- Assert that it now contains no results.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
You'll probably need to use the lobotomize
fixture here to prevent CR from trying to actually scan the non-existent module references in local_unittest_config
.
result = cosmic_ray.cli.main(["init", local_unittest_config, str(session)]) | ||
db=WorkDB(session,2) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
You seem to be comparing the wrong things here. final_count
is the number of results, i.e. the number of work items which have actually been executed. initial_count
is the simply the total number of work items, whether or not they have results attached to them. You need to actually get some results into the workdb for this test to make any sense, and even then you need to make sure you compare the number of results before and after your init call.
thank u so much.....will do the necesarry changes.thx once again |
issue number -#417
changes:-added force flag
added tests