Example #1
0
def test_engrave_duped_scans(fileset_mutable, ok_files, f1_graft, f2_graft, caplog):
    caplog.set_level(0)
    fileset_mutable.chdir()
    cfg = Config()
    cfg.Project.pname = 'prj1'
    cfg.Project.current_version = '0.0.0'
    cfg.Project.version = '0.0.1'
    cfg.Project.engraves = [{
        'globs': ['/a/f*'],
        'grafts': [f1_graft, f1_graft, f2_graft, f2_graft],
    }, {
        'globs': ['b/f1', 'b/?3'],
        'grafts': [f1_graft, f2_graft],
    }, ]
    prj1 = Project(config=cfg)

    cfg.Project.engraves = [{
        'globs': ['/a/f*', '/b/f2', 'b/?3'],
        'grafts': [f1_graft, f2_graft],
    }]
    prj2 = Project(config=cfg)

    fproc = engrave.FileProcessor()
    fproc.scan_projects([prj1, prj2])
    fproc.engrave_matches()
    #print(pformat(match_map))
    assert fproc.nmatches() == 4

    for fpath, text in ok_files.items():
        ftxt = (fileset_mutable / fpath).read_text('utf-8')
        assert ftxt == tw.dedent(text)
Example #2
0
def test_simple_merge(cfg, exp):
    a = A(config=Config(cfg))

    if exp is None:
        assert len(a.a) == 0
    elif isinstance(exp, list):
        assert exp == [e.i for e in a.a]
    else:
        assert a.a[0].i == exp
Example #3
0
def test_default_value():
    class B(Configurable):
        i = Int().tag(config=True)

    class A(Configurable):
        b = AutoInstance(B, default_value={'i': 2}).tag(config=True)

    assert A().b.i == 2

    assert A(config=Config({'A': {'b': {'i': 3}}})).b.i == 3
Example #4
0
def test_dynamic_default():
    class B(Configurable):
        i = Int().tag(config=True)

    class A(Configurable):
        b = AutoInstance(B).tag(config=True)

        @default('b')
        def _get_i(self):
            return dict({'i': 2})

    assert A().b.i == 2

    assert A(config=Config({'A': {'b': {'i': 3}}})).b.i == 3
Example #5
0
def test_scan(fileset_mutable, orig_files, f1_graft, f2_graft, caplog):
    caplog.set_level(0)
    fileset_mutable.chdir()
    cfg = Config()
    cfg.Project.pname = 'prj1'
    cfg.Project.engraves = [{
        'globs': ['/a/f*', 'b/f1', '/b/f2', 'b/?3'],
        'grafts': [f1_graft, f2_graft],
    }]

    prj = Project(config=cfg)
    fproc = engrave.FileProcessor()
    match_map = fproc.scan_projects([prj])
    assert len(match_map) == 6  # nfiles
    #print(pformat(match_map))
    assert fproc.nmatches() == 4

    for fpath, text in orig_files.items():
        ftxt = (fileset_mutable / fpath).read_text('utf-8')
        assert ftxt == tw.dedent(text)
Example #6
0
def test_recursive_merge():
    # Exception a bit confusing...
    cfg = {
        'AA': {
            'aa': [
                {
                    'b': {
                        'i': 1
                    },
                    'bb': {
                        'i': 2
                    }
                },
                {
                    'b': {
                        'i': 11
                    }
                },
                {
                    'bb': {
                        'i': 22
                    }
                },
                {},
            ]
        },
        'B': {
            'b': {
                'i': -1
            },
            'bb': {
                'i': -2
            }
        }
    }
    a = AA(config=Config(cfg))
    assert [el.b.i for el in a.aa] == [1, 11, -1, -1]
    assert [el.bb.i for el in a.aa] == [2, -2, 22, -2]
Example #7
0
def test_smoke():
    cfg = Config({'A': {'a': [{'i': 1}, {}, {'i': 2}]}})
    a = A(config=cfg)
    assert [e.i for e in a.a] == [1, 0, 2]