def test_set_molecule_meta_molecule(prior, meta, expected):
    """
    Test for :func:`SetMoleculeMeta.run_molecule` .
    """
    molecule = Molecule()
    molecule.meta = copy.copy(prior)
    processor = SetMoleculeMeta(**meta)
    processor.run_molecule(molecule)
    assert not are_different(molecule.meta, expected)
def test_set_molecule_meta_system(priors, meta, expected):
    """
    Test for :func:`SetMoleculeMeta.run_system` .
    """
    system = System()
    for prior in priors:
        molecule = Molecule()
        molecule.meta = copy.copy(prior)
        system.add_molecule(molecule)
    processor = SetMoleculeMeta(**meta)
    processor.run_system(system)
    for molecule, expectation in zip(system.molecules, expected):
        assert not are_different(molecule.meta, expectation)
def compare_dicts(testee, reference):
    """
    Report differences between dictionaries.
    """
    report = []
    dict_equals = testee.keys() == reference.keys()
    diff_keys = []
    if dict_equals:
        for key in testee:
            if are_different(testee[key], reference[key]):
                diff_keys.append(key)
    if diff_keys:
        report.append('The following keys differ: {}'.format(diff_keys))
    if diff_keys or not dict_equals:
        report.append('+ {}'.format(testee))
        report.append('- {}'.format(reference))
    return report
def generate_diff_dict(draw):
    """
    Strategy to generate to similar but different dictionaries.
    """
    dict_a = draw(generate_dict(min_size=1))
    dict_b = copy.deepcopy(dict_a)
    values = st.one_of(
        st.text(), st.integers(), st.floats(),
        hnp.arrays(dtype=hnp.scalar_dtypes(), shape=hnp.array_shapes()))
    num_to_change = draw(
        st.integers(min_value=1, max_value=(len(dict_b) // 2) + 1))
    for _ in range(num_to_change):
        key = draw(st.sampled_from(list(dict_b.keys())))
        new_val = draw(values)
        assume(are_different(new_val, dict_a[key]))
        dict_b[key] = new_val
    dict_c = draw(generate_dict())
    for key in set(dict_c.keys()) - set(dict_b.keys()):
        dict_b[key] = dict_c[key]
    return dict_a, dict_b
Exemple #5
0
def test_are_different_custom(left, right, expected):
    """
    Test :func:`are_different` on handcrafted cases.
    """
    assert utils.are_different(left, right) == expected
Exemple #6
0
def test_not_are_different(left):
    """
    Test that :func:`are_different` returns False for equal values.
    """
    assert not utils.are_different(left, left)
Exemple #7
0
def test_are_different(left, right):
    """
    Test that :func:`are_different` identify different values.
    """
    assert utils.are_different(left, right)