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

trying to fix-Init should refuse if there are existing results #560

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

muhd360
Copy link

@muhd360 muhd360 commented Oct 28, 2024

issue number -#417
changes:-added force flag
added tests

@@ -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:
Copy link
Contributor

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.

@muhd360
Copy link
Author

muhd360 commented Oct 28, 2024 via email

@@ -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):
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Author

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

@muhd360
Copy link
Author

muhd360 commented Oct 29, 2024

hi @abingham for the case when force is false what will the test case reflect is creating a mockdb the right kind of approach???

@muhd360
Copy link
Author

muhd360 commented Oct 30, 2024

@abingham ???

@abingham
Copy link
Contributor

hi @abingham for the case when force is false what will the test case reflect is creating a mockdb the right kind of approach???

A test for the force == False case would not require a mock database. You could create a normal workdb, get some results into it, and then verify that running init with force == False aborts and does not re-init the database, i.e. it would leave the database unchanged.

@muhd360
Copy link
Author

muhd360 commented Oct 31, 2024

ok will do

@muhd360
Copy link
Author

muhd360 commented Oct 31, 2024

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
Copy link
Contributor

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",
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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):
Copy link
Contributor

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"""
Copy link
Contributor

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:

  1. Create the WorkDB
  2. Put some results into it and verify that it has the results
  3. Re-initialize it with --force
  4. 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):
Copy link
Contributor

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
Copy link
Contributor

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.

@muhd360
Copy link
Author

muhd360 commented Nov 1, 2024

thank u so much.....will do the necesarry changes.thx once again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants