Ejemplo n.º 1
0
def test_realize_dependencies() -> None:
    with setup_storage2('test_realize_dependencies') as (T, S):
        n1 = None
        n2 = None
        n3 = None
        toplevel = None

        def _setup(m):
            nonlocal n1, n2, n3, toplevel
            n1 = mkstage(m, {'a': 1})
            n2 = mkstage(m, {'parent1': n1})
            n3 = mkstage(m, {'parent2': n1})
            toplevel = mkstage(m, {'n2': n2, 'n3': n3})
            return toplevel

        rref = realize(instantiate(_setup, S=S))
        assert_valid_rref(rref)
        assert n1 is not None
        assert n2 is not None
        assert n3 is not None
        assert toplevel is not None

        c = store_config(rref, S)
        assert_valid_config(c)
        cro = store_cattrs(rref, S)
        assert_valid_dref(getattr(cro, 'n2'))
        assert_valid_dref(getattr(cro, 'n3'))

        assert set(store_deps([n1], S)) == set([])
        assert set(store_deps([n2, n3], S)) == set([n1])
        assert set(store_deps([toplevel], S)) == set([n2, n3])

        assert store_deepdeps([n1], S) == set([])
        assert store_deepdeps([n2, n3], S) == set([n1])
        assert store_deepdeps([toplevel], S) == set([n1, n2, n3])
Ejemplo n.º 2
0
def test_repl_race():
    with setup_storage('test_repl_recursion'):

        def _setting(m: Manager) -> DRef:
            n1 = mkstage(m, {'a': '1'})
            n2 = mkstage(m, {'maman': n1})
            return n2

        clo = instantiate(_setting)
        rh = repl_realize(clo, force_interrupt=True)
        assert repl_rref(rh) is None
        assert rh.dref == clo.dref

        clo2 = instantiate(_setting)
        rref2 = realize(clo2)  # Realize dref while repl_realizing same dref

        repl_cancel(rh)
        assert_valid_rref(rref2)
Ejemplo n.º 3
0
def test_realize_base(d) -> None:
    with setup_storage2('test_realize_base') as (T, S):
        m = Manager(storage(S))
        mkstage(m, d)
        dref = list(m.builders.values())[-1].dref
        assert_valid_dref(dref)
        assert len(list(store_rrefs(dref, mkcontext(), S))) == 0
        rrefgs = list(m.builders.values())[-1].matcher(S, dref, mkcontext())
        assert rrefgs is None
        rrefg = mkrgroup(
            dref, mkcontext(),
            list(m.builders.values())[-1].realizer(S, dref, mkcontext(),
                                                   {})[0], S)
        assert len(list(store_rrefs(dref, mkcontext(), S))) == 1
        assert_valid_rref(rrefg[Tag('out')])
        rrefgs2 = list(m.builders.values())[-1].matcher(S, dref, mkcontext())
        assert rrefgs2 is not None
        rrefg2 = rrefgs2[0]
        assert rrefg == rrefg2
Ejemplo n.º 4
0
def test_inplace():
    with setup_storage('test_inplace'):
        setup_inplace_reset()

        n1 = instantiate_inplace(mkstage, {'a': '1'})
        n2 = instantiate_inplace(mkstage, {'b': '2'})
        n3 = instantiate_inplace(mkstage, {'c': '3', 'maman': n1})
        n4 = instantiate_inplace(mkstage, {'c': '4', 'papa': n3})
        assert_valid_dref(n3)
        assert_valid_dref(n4)

        rref_n3 = realize_inplace(n3)
        assert_valid_rref(rref_n3)

        all_drefs = list(alldrefs())
        assert len(all_drefs) == 4
        assert len(list(store_rrefs_(n1))) == 1
        assert len(list(store_rrefs_(n2))) == 0
        assert len(list(store_rrefs_(n3))) == 1
        assert len(list(store_rrefs_(n4))) == 0
Ejemplo n.º 5
0
def test_promise() -> None:
    with setup_storage2('test_promise') as (T, S):

        def _setting(m: Manager, fullfill: bool) -> DRef:
            n1 = mkstage(m, {'name': '1', 'promise': [promise, 'artifact']})

            def _realize(b: Build):
                o = build_outpath(b)
                c = build_cattrs(b)
                assert b.dref in c.promise
                assert n1 in store_cattrs(c.maman, S).promise
                assert build_path(b, c.promise) == join(o, 'uber-artifact')
                assert build_path(b,
                                  store_cattrs(c.maman,
                                               S).promise) == build_path(
                                                   b, c.maman_promise)
                if fullfill:
                    with open(build_path(b, c.promise), 'w') as f:
                        f.write('chickenpoop')

            return mkdrv(m,
                         mkconfig({
                             'name': '2',
                             'maman': n1,
                             'promise': [promise, 'uber-artifact'],
                             'maman_promise': [n1, 'artifact']
                         }),
                         matcher=match_some(),
                         realizer=build_wrapper(_realize))

        try:
            rref = realize(instantiate(_setting, False, S=S))
            raise ShouldHaveFailed('Promise trigger')
        except AssertionError:
            pass
        rref = realize(instantiate(_setting, True, S=S))
        assert_valid_rref(rref)
Ejemplo n.º 6
0
def test_lens():
  with setup_storage('test_lens'):
    def _setting(m:Manager)->DRef:
      n1=mkstage(m, {'name':'1', 'promise':[promise,'artifact']})
      n2=mkstage(m, {'name':'2', 'promise':[promise,'artifact'],
                        'dict':{'d1':1} })

      def _realize(b:Build):
        o=build_outpath(b)
        c=build_cattrs(b)
        assert isrefpath(mklens(b).maman.promise.refpath)
        assert isfile(mklens(b).papa.promise.syspath)
        assert o in mklens(b).promise.syspath
        assert o == mklens(b).syspath
        assert mklens(b).papa.name.val == '2'
        assert mklens(b).papa.dref == c.papa

        with open(mklens(b).promise.syspath,'w') as f:
          f.write('chickenpoop')

      return mkdrv(m,
        mkconfig({'name':'3', 'maman':n1, 'papa':n2,
                  'promise':[promise,'artifact'],
                  }),
                 matcher=match_some(),
                 realizer=build_wrapper(_realize))

    clo=instantiate(_setting)
    assert isrefpath(mklens(clo.dref).maman.promise.refpath)
    assert isdir(mklens(clo.dref).syspath)
    rref=realize(clo)
    assert_valid_rref(rref)
    assert isrefpath(mklens(rref).maman.promise.refpath)
    assert isfile(mklens(rref).maman.promise.syspath)
    assert mklens(rref).rref == rref
    assert isrefpath(mklens(rref).papa.promise.refpath)
    assert mklens(rref).papa.dict.d1.val == 1
    assert mklens(rref).dref == clo.dref
    assert isdir(mklens(rref).syspath)

    try:
      print(mklens(clo.dref).maman.promise.syspath)
      raise ShouldHaveFailed()
    except AssertionError:
      pass

    try:
      print(mklens(rref).papa.dict.d1.get('xxx'))
      raise ShouldHaveFailed()
    except AssertionError:
      pass

    try:
      print(mklens(rref).papa.dict.d1.syspath)
      raise ShouldHaveFailed()
    except AssertionError:
      pass

    try:
      mklens(rref).papa.dict.d1.val=42 # can't mutate rref
      raise ShouldHaveFailed()
    except AssertionError:
      pass

    d={'foo':'foo','bar':'bar'}
    mklens(d).foo.val='zzz'
    assert d['foo']=='zzz'
    try:
      mklens(d).x.val=42 # can't set new values
      raise ShouldHaveFailed()
    except AssertionError:
      pass
    mklens(d).bar.val+='33'
    assert d['bar']=='bar33'