Beispiel #1
0
def process():
    """Active code referred to via entry_points function"""
    parser = ArgumentParser(description="Display final state of shelves.")
    parser.add_argument('--reactions',
                        '-r',
                        action="store_true",
                        help="Display only the number of reactions.")
    parser.add_argument('filepath',
                        help="Input two-shelf laboratory file in yaml format.")
    args = parser.parse_args()

    check_ext(args.filepath)

    with open(args.filepath) as file:
        labdict = yaml.load(file)

    check_dict(labdict)

    check_keys(labdict)

    lab = Laboratory(labdict['lower'], labdict['upper'])
    count, final_shelves = lab.all_reactions()
    if args.reactions:
        print("{}".format(count))
    else:
        print("lower: {}\nupper: {}".format(*final_shelves))
Beispiel #2
0
def process():
    """
    """
    parser = ArgumentParser(description="")

    # optional argument, when passed the value True is stored.
    parser.add_argument('--reactions',
                        '-r',
                        action="store_true",
                        help="returns the number of reactions.")

    # mandatory argument, which holds the laboratory in a yaml file
    parser.add_argument('yaml_file',
                        help="laboratory stored as a yaml" + "file")

    arguments = parser.parse_args()

    dict_lab = yaml.load(open(arguments.yaml_file))

    # instantiates a new laboratory object using the dictionary from
    # the yaml_file arguemnet
    lab = Laboratory(dict_lab)

    if (arguments.reactions):
        print(lab.run_full_experiment(arguments.reactions))
    else:
        lab.run_full_experiment(arguments.reactions)
        print(yaml.dump({'lower': lab.lower, 'upper': lab.upper}))
def test_random_selections():
    lower = ['antia']
    upper = ['a', 'b', 'a', 'c', 'a', 'c', 'a', 'd', 'a', 'b', 'a', 'c', 'a']
    testlab2 = Laboratory(lower, upper)
    answer = testlab2.do_a_reaction()
    assert answer[1].count('a') == 6
    for substance in answer[1]:
        if substance == 'a':
            answer[1].remove('a')
    assert answer[1] == ['b', 'c', 'c', 'd', 'b', 'c']
Beispiel #4
0
def test_laboratory_single_reaction(test_input, expected):
    """
    Test that a single reaction is correctly computed, with the shelves
        updated accordingly.
    """
    lab = Laboratory(test_input)

    result = lab._single_reaction()

    assert result == expected
Beispiel #5
0
def test_laboratory_run_experiment(test_input, expected_count,
                                   expected_output):
    """
    Check that a full experiment is run, until all substances which can
        react have done so. Check that the number of reactions is
        computed correctly.
    """
    lab = Laboratory(test_input)

    result = lab.run_experiment()

    assert lab.reaction_count == expected_count
    assert result == expected_output
Beispiel #6
0
def process():
    parser = ArgumentParser(description=
                            "Show results of reactions / number of reactions")
    parser.add_argument('laboratory')
    parser.add_argument('--reactions', '-r', action="store_true")
    arguments = parser.parse_args()
    if arguments.laboratory:
        with open(arguments.laboratory, "r") as data:
            shelves = yaml.load(data)
        mylab = Laboratory(shelves["lower"], shelves["upper"])
        count = mylab.run_full_experiment()
        if arguments.reactions:
            print(count)
        else:
            print("lower: {} \nupper: {}".format(mylab.lower_shelf,
                  mylab.upper_shelf))
Beispiel #7
0
def test_laboratory_find_possible_targets(test_input, test_substance,
                                          expected):
    """
    Test that we the find_possible_targets method with different cases.
        Does so by asserting that the set of results of potential
        targets overlaps with what we expect, accounting for potentially
        random target selection with multiple possible targets.
    """
    lab = Laboratory(test_input, reaction_type='simple')

    upper = lab.upper

    result = lab._find_possible_targets(test_substance, upper)

    if expected:
        assert set(result).intersection(set(expected))
    else:
        assert result == expected
Beispiel #8
0
def test_improper_laboratory_instantiation():
    """
    Test that an error is raised if a Laboratory object is not
        correctly instantiated.
    """
    error_message = "TypeError: __init__() missing 1 required positional" \
                    " argument: 'substance_data'"

    with pytest.raises(Exception) as e_info:
        Laboratory()
        assert error_message in str(e_info.value)
Beispiel #9
0
def test_laboratory_instantiation(test_input):
    """
    Test that a Laboratory object is properly instantiated when input
        with with some substance data.
    """
    lab = Laboratory(test_input)

    assert hasattr(lab, 'check_reaction_func')
    assert hasattr(lab, 'reaction_count')
    assert hasattr(lab, 'lower')
    assert hasattr(lab, 'upper')
def test_do_a_reaction_shelf_type():
    with raises(TypeError) as exception:
        Laboratory.do_a_reaction(Laboratory, ('a', 'b'),
                                 ['antia', 'antic', 'd'])
def test_init_antianti():
    with raises(ValueError) as exception:
        Laboratory(['antiantia'], ['a'])
        Laboratory(['a'], ['antiantia'])
def test_init_no_empty_strings():
    with raises(ValueError) as exception:
        Laboratory(['a'], [''])
        Laboratory(['anti'], ['a'])
def test_init_shelf_type():
    with raises(TypeError) as exception:
        Laboratory(['a'], 'b')
        Laboratory(('a'), ['b'])
from pytest import raises

from alchemist.laboratory import update_shelves, can_react, Laboratory

TEST_LAB = Laboratory(['a', 'b', 'c'], ['antia', 'antic', 'd'])


def test_init():
    assert isinstance(TEST_LAB, Laboratory)
    assert TEST_LAB.lower_shelf == ['a', 'b', 'c']
    assert TEST_LAB.upper_shelf == ['antia', 'antic', 'd']


def test_init_shelf_type():
    with raises(TypeError) as exception:
        Laboratory(['a'], 'b')
        Laboratory(('a'), ['b'])


def test_init_no_empty_strings():
    with raises(ValueError) as exception:
        Laboratory(['a'], [''])
        Laboratory(['anti'], ['a'])


def test_init_antianti():
    with raises(ValueError) as exception:
        Laboratory(['antiantia'], ['a'])
        Laboratory(['a'], ['antiantia'])