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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/cosmic_ray/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ def new_config(config_file):


@cli.command()
@click.argument("force", type=bool, default=False)
@click.argument("config_file")
@click.argument(
"session_file",
# help="The filename for the database in which the work order will be stored."
)
def init(config_file, session_file):
def init(config_file, session_file,force):
"""Initialize a mutation testing session from a configuration. This
primarily creates a session - a database of "work to be done" -
which describes all of the mutations and test runs that need to be
Expand Down Expand Up @@ -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.

sys.exit(ExitCode.OK)
elif database.num_results==0 or force:
cosmic_ray.commands.init(modules, database, operators_cfg)


sys.exit(ExitCode.OK)

Expand Down
24 changes: 19 additions & 5 deletions tests/unittests/test_command_line_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
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, use_db

@pytest.fixture
def config_file(tmpdir):
Expand Down Expand Up @@ -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.

cosmic_ray.cli.main(["init", local_unittest_config, str(session),force])
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,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

result = cosmic_ray.cli.main(["init", local_unittest_config, str(session),force])
assert result == ExitCode.OK
def test_init_with_existing_results_force(session, local_unittest_config,force=True):
"""Test that init exits without reinitializing when results exist and force=False"""

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")
Expand All @@ -80,8 +94,8 @@ def test_new_config_success_returns_EX_OK(monkeypatch, config_file):
# NOTE: We have integration tests for the happy-path for many commands, so we don't cover them explicitly here.


def test_dump_success_returns_EX_OK(lobotomize, local_unittest_config, session):
errcode = cosmic_ray.cli.main(["init", local_unittest_config, str(session)])
def test_dump_success_returns_EX_OK(lobotomize, local_unittest_config, session,force):
errcode = cosmic_ray.cli.main(["init", local_unittest_config, str(session),force])
assert errcode == ExitCode.OK

errcode = cosmic_ray.cli.main(["dump", str(session)])
Expand Down