Beispiel #1
0
def test_compositional_dump():
    a = CompoundExecutor()
    a.components = lambda: [BaseExecutor(), BaseExecutor()]
    assert a.name
    a.touch()
    a.save()
    a.save_config()
    assert Path(a.save_abspath).exists()
    assert Path(a.config_abspath).exists()
    rm_files([a.save_abspath, a.config_abspath])
Beispiel #2
0
def test_compositional_dump(test_metas):
    a = CompoundExecutor(metas=test_metas)
    a.components = lambda: [BaseExecutor(), BaseExecutor()]
    assert a.name
    a.touch()
    a.save()
    a.save_config()
    assert os.path.exists(a.save_abspath)
    assert os.path.exists(a.config_abspath)
    rm_files([a.save_abspath, a.config_abspath])
Beispiel #3
0
 def test_compositional_dump(self):
     a = CompoundExecutor()
     a.components = lambda: [BaseExecutor(), BaseExecutor()]
     self.assertIsNotNone(a.name)
     self.tmp_files.append(a.save_abspath)
     self.tmp_files.append(a.config_abspath)
     a.touch()
     a.save()
     a.save_config()
     self.assertTrue(os.path.exists(a.save_abspath))
     self.assertTrue(os.path.exists(a.config_abspath))
Beispiel #4
0
    def test_compositional_route(self):
        da = dummyA()
        db = dummyB()
        a = CompoundExecutor()

        a.components = lambda: [da, db]
        assert a.say_all() == ['a', 'b']
        with self.assertRaises(AttributeError):
            a.say()

        b = CompoundExecutor({'say': {da.name: 'say'}})
        b.components = lambda: [da, db]
        assert b.say_all() == ['a', 'b']
        assert b.say() == 'a'
        b.add_route('say', db.name, 'say')
        assert b.say() == 'b'
        b.save_config()
        self.assertTrue(os.path.exists(b.config_abspath))

        c = BaseExecutor.load_config(b.config_abspath)
        assert c.say_all() == ['a', 'b']
        assert c.say() == 'a'

        b.add_route('say', db.name, 'say', is_stored=True)
        b.save_config()
        c = BaseExecutor.load_config(b.config_abspath)
        assert c.say_all() == ['a', 'b']
        assert c.say() == 'b'

        b.touch()
        b.save()
        self.assertTrue(os.path.exists(b.save_abspath))

        d = BaseExecutor.load(b.save_abspath)
        assert d.say_all() == ['a', 'b']
        assert d.say() == 'b'

        self.tmp_files.append(b.config_abspath)
        self.tmp_files.append(b.save_abspath)
Beispiel #5
0
def test_compositional_route(monkeypatch):
    monkeypatch.setattr(BaseExecutor, 'exec_methods', ['say'])
    da = DummyA()
    db = DummyB()
    a = CompoundExecutor()

    a.components = lambda: [da, db]
    assert a.say_all() == ['a', 'b']
    with pytest.raises(AttributeError):
        a.say()

    b = CompoundExecutor({'say': {da.name: 'say'}})
    b.components = lambda: [da, db]
    assert b.say_all() == ['a', 'b']
    assert b.say() == 'a'
    b.add_route('say', db.name, 'say')
    assert b.say() == 'b'
    b.save_config()
    assert Path(b.config_abspath).exists()

    c = BaseExecutor.load_config(b.config_abspath)
    assert c.say_all() == ['a', 'b']
    assert c.say() == 'a'

    b.add_route('say', db.name, 'say', is_stored=True)
    b.save_config()
    c = BaseExecutor.load_config(b.config_abspath)
    assert c.say_all() == ['a', 'b']
    assert c.say() == 'b'

    b.touch()
    b.save()
    assert Path(b.save_abspath).exists()

    d = BaseExecutor.load(b.save_abspath)
    assert d.say_all() == ['a', 'b']
    assert d.say() == 'b'

    rm_files([b.save_abspath, b.config_abspath])