Exemplo n.º 1
0
 def test_gateway_and_id(self):
     group = Group()
     gw = group.makegateway("popen//id=hello")
     assert group["hello"] == gw
     py.test.raises((TypeError, AttributeError), "del group['hello']")
     py.test.raises((TypeError, AttributeError), "group['hello'] = 5")
     assert 'hello' in group
     assert gw in group
     assert len(group) == 1
     gw.exit()
     assert 'hello' not in group
     py.test.raises(KeyError, "group['hello']")
Exemplo n.º 2
0
 def test_group_id_allocation(self):
     group = Group()
     specs = [XSpec("popen"), XSpec("popen//id=hello")]
     group.allocate_id(specs[0])
     group.allocate_id(specs[1])
     gw = group.makegateway(specs[1])
     assert gw.id == "hello"
     gw = group.makegateway(specs[0])
     assert gw.id == "gw0"
     # py.test.raises(ValueError,
     #    group.allocate_id, XSpec("popen//id=hello"))
     group.terminate()
Exemplo n.º 3
0
 def test_group_ordering_and_termination(self):
     group = Group()
     group.makegateway("popen//id=3")
     group.makegateway("popen//id=2")
     group.makegateway("popen//id=5")
     gwlist = list(group)
     assert len(gwlist) == 3
     idlist = [x.id for x in gwlist]
     assert idlist == list("325")
     print(group)
     group.terminate()
     print(group)
     assert not group
     assert repr(group) == "<Group []>"
Exemplo n.º 4
0
 def test_gateway_and_id(self):
     group = Group()
     gw = group.makegateway("popen//id=hello")
     assert group["hello"] == gw
     with pytest.raises((TypeError, AttributeError)):
         del group["hello"]
     with pytest.raises((TypeError, AttributeError)):
         group["hello"] = 5
     assert "hello" in group
     assert gw in group
     assert len(group) == 1
     gw.exit()
     assert "hello" not in group
     with pytest.raises(KeyError):
         _ = group["hello"]
Exemplo n.º 5
0
    def test_basic_group(self, monkeypatch):
        import atexit

        atexitlist = []
        monkeypatch.setattr(atexit, "register", atexitlist.append)
        group = Group()
        assert atexitlist == [group._cleanup_atexit]
        exitlist = []
        joinlist = []

        class PseudoIO:
            def wait(self):
                pass

        class PseudoSpec:
            via = None

        class PseudoGW:
            id = "9999"
            _io = PseudoIO()
            spec = PseudoSpec()

            def exit(self):
                exitlist.append(self)
                group._unregister(self)

            def join(self):
                joinlist.append(self)

        gw = PseudoGW()
        group._register(gw)
        assert len(exitlist) == 0
        assert len(joinlist) == 0
        group._cleanup_atexit()
        assert len(exitlist) == 1
        assert exitlist == [gw]
        assert len(joinlist) == 1
        assert joinlist == [gw]
        group._cleanup_atexit()
        assert len(exitlist) == 1
        assert len(joinlist) == 1
Exemplo n.º 6
0
 def test_terminate_with_proxying(self):
     group = Group()
     group.makegateway("popen//id=master")
     group.makegateway("popen//via=master//id=worker")
     group.terminate(1.0)
Exemplo n.º 7
0
 def test_group_default_spec(self):
     group = Group()
     group.defaultspec = "not-existing-type"
     py.test.raises(ValueError, group.makegateway)
Exemplo n.º 8
0
 def test_terminate_with_proxying(self):
     group = Group()
     group.makegateway('popen//id=master')
     group.makegateway('popen//via=master//id=slave')
     group.terminate(1.0)