Exemple #1
0
 def test_group_PopenGateway(self):
     group = Group()
     gw = group.makegateway("popen")
     assert list(group) == [gw]
     assert group[0] == gw
     assert len(group) == 1
     group._cleanup_atexit()
     assert not group._gateways
Exemple #2
0
 def test_group_PopenGateway(self):
     group = Group()
     gw = group.makegateway("popen")
     assert list(group) == [gw]
     assert group[0] == gw
     assert len(group) == 1
     group._cleanup_atexit()
     assert not group._gateways
Exemple #3
0
    def test_remote_exec_args(self):
        group = Group()
        group.makegateway('popen')

        def fun(channel, arg):
            channel.send(arg)
        mch = group.remote_exec(fun, arg=1)
        result = mch.receive_each()
        assert result == [1]
Exemple #4
0
    def test_remote_exec_args(self):
        group = Group()
        group.makegateway('popen')

        def fun(channel, arg):
            channel.send(arg)
        mch = group.remote_exec(fun, arg=1)
        result = mch.receive_each()
        assert result == [1]
Exemple #5
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']")
Exemple #6
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']")
Exemple #7
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"]
Exemple #8
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()
Exemple #9
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 []>"
Exemple #10
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()
Exemple #11
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 []>"
Exemple #12
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
Exemple #13
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
Exemple #14
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)
Exemple #15
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)
Exemple #16
0
 def test_group_default_spec(self):
     group = Group()
     group.defaultspec = "not-existing-type"
     py.test.raises(ValueError, group.makegateway)
Exemple #17
0
 def test_group_default_spec(self):
     group = Group()
     group.defaultspec = "not-existing-type"
     py.test.raises(ValueError, group.makegateway)
Exemple #18
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)