Пример #1
0
def test_constants_are_restored_after_subproject_deactivation(prj, main_const):
    """ After subproject deactivation, project's original constants return. """
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
    prj.activate_subproject("with_const")
    assert main_const != prj[CONSTANTS_DECLARATION].to_dict()
    prj.deactivate_subproject()
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
Пример #2
0
 def test_does_not_need_all_sample_independent_data(
         self, sections, basic_project_data, sample_independent_data):
     """ Subset of all known independent data that's present is grabbed. """
     p = PathExAttMap(sample_independent_data)
     expected = {s: data for s, data in basic_project_data.items()
                 if s in sections}
     observed = grab_project_data(p)
     compare_mappings(expected, observed)
Пример #3
0
def test_constants_are_overwritten_by_subproject(prj, main_const):
    """ A subproject's constants take precedence over existing. """
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
    prj.activate_subproject("with_const")
    obs = prj[CONSTANTS_DECLARATION]
    assert obs.to_dict() != main_const
    assert {"const1", "unreplaced"} == set(obs.keys())
    assert "preserved" == obs["unreplaced"]
    assert obs["const1"] != "should-be-replaced"
    assert SUBS1["const1"] == obs["const1"]
Пример #4
0
    def test_grabs_only_sample_independent_data(
            self, sample_independent_data, extra_data):
        """ Only Project data defined as Sample-independent is retrieved. """

        # Create the data to pass the the argument to the call under test.
        data = copy.deepcopy(sample_independent_data)
        data_updates = {}
        for extra in extra_data:
            data_updates.update(extra)
        data.update(data_updates)

        # Convert to the correct argument type for this test case.
        p = PathExAttMap(data)

        # Make the equivalence assertion.
        expected = sample_independent_data
        observed = grab_project_data(p)
        compare_mappings(expected, observed)
Пример #5
0
def prj(tmpdir, request):
    """ Create Project after writing config in given tempfolder. """
    tmp = tmpdir.strpath
    assert os.path.isdir(tmp)
    main_const = request.getfixturevalue("main_const")
    data = {METADATA_KEY: {OUTDIR_KEY: tmp}, SUBPROJECTS_SECTION: SUBP_MAP}
    cfg = os.path.join(tmp, "pc.yaml")
    assert not os.path.exists(cfg), "Config path already exists: {}".format(
        cfg)
    if main_const:
        data[CONSTANTS_DECLARATION] = main_const
        check = lambda p: compare_mappings(main_const, p[CONSTANTS_DECLARATION]
                                           )
    else:
        check = lambda p: {} == CONSTANTS_DECLARATION
    with open(cfg, 'w') as f:
        yaml.dump(data, f)
    p = Project(cfg)
    check(p)
    return p
Пример #6
0
def test_empty_subprojects_dont_squash_existing(prj, main_const):
    """ Subproject with empty constants leaves initial constants unchanged. """
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
    prj.activate_subproject("without_const")
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
Пример #7
0
def test_constants_survive_activation_of_subproject_without_constants(
        prj, main_const):
    """ Constants survive if extant and subproject declares none. """
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
    prj.activate_subproject("without_const")
    compare_mappings(main_const, prj[CONSTANTS_DECLARATION])
Пример #8
0
def test_subproject_introduces_constants(prj, subp, expected, main_const):
    """ A subproject can add constant to a Project that lacked them. """
    assert not prj[CONSTANTS_DECLARATION]
    prj.activate_subproject(subp)
    compare_mappings(expected, prj[CONSTANTS_DECLARATION])