Exemplo n.º 1
0
    def test_clear(self):
        d = ServiceOptsDict(
            {"omero.group": -1, "omero.user": 1, "omero.share": 2})
        d.clear()
        assert d == {}

        pytest.raises(TypeError, d.clear, None)
Exemplo n.º 2
0
    def test_clear(self):
        d = ServiceOptsDict(
            {"omero.group": -1, "omero.user": 1, "omero.share": 2})
        d.clear()
        assert d == {}

        pytest.raises(TypeError, d.clear, None)
Exemplo n.º 3
0
    def test_keys(self):
        d = ServiceOptsDict()
        assert d.keys() == []

        d = ServiceOptsDict({"omero.group": -1})
        assert 'omero.group' in d

        pytest.raises(TypeError, d.keys, None)
Exemplo n.º 4
0
    def test_has_key(self):
        d = ServiceOptsDict()
        assert 'omero' not in d

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        k = list(d.keys())
        k.sort()
        assert k == ['omero.group', 'omero.user']
Exemplo n.º 5
0
    def test_keys(self):
        d = ServiceOptsDict()
        assert d.keys() == []

        d = ServiceOptsDict({"omero.group": -1})
        assert 'omero.group' in d

        pytest.raises(TypeError, d.keys, None)
Exemplo n.º 6
0
    def test_items(self):
        d = ServiceOptsDict()
        self.assertEqual(d.items(), [])

        d = ServiceOptsDict({"omero.group":-1})
        self.assertEqual(d.items(), [("omero.group", "-1")])

        self.assertRaises(TypeError, d.items, None)
Exemplo n.º 7
0
 def test_keys(self):
     d = ServiceOptsDict()
     self.assertEqual(d.keys(), [])
     
     d = ServiceOptsDict({"omero.group":-1})
     k = d.keys()
     self.assert_(d.has_key('omero.group'))
     
     self.assertRaises(TypeError, d.keys, None)
Exemplo n.º 8
0
 def test_contains(self):
     d = ServiceOptsDict()
     assert not ('omero.group' in d)
     assert 'omero.group' not in d
     
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1})
     assert 'omero.group' in d
     assert 'omero.user' in d
     assert 'omero.share' not in d
Exemplo n.º 9
0
    def test_contains(self):
        d = ServiceOptsDict()
        self.assert_(not ('omero.group' in d))
        self.assert_('omero.group' not in d)

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        self.assert_('omero.group' in d)
        self.assert_('omero.user' in d)
        self.assert_('omero.share' not in d)
Exemplo n.º 10
0
 def test_has_key(self):
     d = ServiceOptsDict()
     self.assert_(not d.has_key('omero'))
     
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1})
     k = d.keys()
     k.sort()
     self.assertEqual(k, ['omero.group', 'omero.user'])
     
     self.assertRaises(TypeError, d.has_key)
Exemplo n.º 11
0
    def test_has_key(self):
        d = ServiceOptsDict()
        assert "omero" not in d

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        k = d.keys()
        k.sort()
        assert k == ["omero.group", "omero.user"]

        pytest.raises(TypeError, d.has_key)
Exemplo n.º 12
0
    def test_clear(self):
        d = ServiceOptsDict({
            "omero.group": -1,
            "omero.user": 1,
            "omero.share": 2
        })
        d.clear()
        self.assertEqual(d, {})

        self.assertRaises(TypeError, d.clear, None)
Exemplo n.º 13
0
    def test_copy(self):
        def getHash(obj):
            return hex(id(obj))

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1, "omero.share": 2})
        assert d.copy() == d
        assert getHash(d.copy()) != getHash(d)
        assert ServiceOptsDict().copy() == ServiceOptsDict()
        assert getHash(ServiceOptsDict().copy()) != getHash(ServiceOptsDict())
        pytest.raises(TypeError, d.copy, None)
Exemplo n.º 14
0
 def test_has_key(self):
     d = ServiceOptsDict()
     assert not d.has_key('omero')
     
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1})
     k = d.keys()
     k.sort()
     assert k ==  ['omero.group', 'omero.user']
     
     pytest.raises(TypeError, d.has_key)
Exemplo n.º 15
0
    def test_has_key(self):
        d = ServiceOptsDict()
        assert 'omero' not in d

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        k = d.keys()
        k.sort()
        assert k == ['omero.group', 'omero.user']

        pytest.raises(TypeError, d.has_key)
Exemplo n.º 16
0
 def test_copy(self):
     
     def getHash(obj):
         return hex(id(obj))
     
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1, "omero.share": 2})
     self.assertEqual(d.copy(), d)
     self.assertNotEqual(getHash(d.copy()), getHash(d))
     self.assertEqual(ServiceOptsDict().copy(), ServiceOptsDict())
     self.assertEqual(getHash(ServiceOptsDict().copy()), getHash(ServiceOptsDict()))
     self.assertRaises(TypeError, d.copy, None)
Exemplo n.º 17
0
 def test_values(self):
     d = ServiceOptsDict()
     assert d.values() ==  []
     
     d = ServiceOptsDict({"omero.group":-1})
     assert d.values() ==  ["-1"]
     
     pytest.raises(TypeError, d.values, None)
     
     d = ServiceOptsDict({"a":None, "b":True, "c":"foo", "d":1, "e":1.45, "f":[], "g":{}})
     assert d.values() ==  ['foo', '1.45', '1']
Exemplo n.º 18
0
 def test_constructor(self):
     self.assertEqual(ServiceOptsDict(), {})
     self.assert_(ServiceOptsDict() is not {})
     self.assert_(ServiceOptsDict() is not dict())
     
     d = {"omero.group":-1}
     d = ServiceOptsDict(d)
     
     resd = d.get("omero.group")
     self.assert_(isinstance(resd, str))
     self.assertEqual(d.get("omero.group"), str(d["omero.group"]))
     
     d = ServiceOptsDict(x=1,y=2)
     self.assertEqual(d.get("x"), "1")
     self.assertEqual(d.get("y"), "2")
Exemplo n.º 19
0
 def test_getitem(self):
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1})
     assert d["omero.group"] ==  "-1"
     assert d["omero.user"] ==  "1"
     
     d["omero.share"] = 2
     d["foo"] = "bar"
     assert d["omero.share"] ==  "2"
     assert d["foo"] ==  "bar"
     
     del d["omero.user"]
     
     assert d ==  {"omero.group": "-1", 'foo': 'bar', "omero.share": "2"}
     
     pytest.raises(TypeError, d.__getitem__)
     
     assert d.get("omero.user") ==  None
     assert d.get("omero.user", "5"), "5"
Exemplo n.º 20
0
 def test_getitem(self):
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1})
     self.assertEqual(d["omero.group"], "-1")
     self.assertEqual(d["omero.user"], "1")
     
     d["omero.share"] = 2
     d["foo"] = "bar"
     self.assertEqual(d["omero.share"], "2")
     self.assertEqual(d["foo"], "bar")
     
     del d["omero.user"]
     
     self.assertEqual(d, {"omero.group": "-1", 'foo': 'bar', "omero.share": "2"})
     
     self.assertRaises(TypeError, d.__getitem__)
     
     self.assertEqual(d.get("omero.user"), None)
     self.assertEqual(d.get("omero.user", "5"), "5")
Exemplo n.º 21
0
 def test_copy(self):
     
     def getHash(obj):
         return hex(id(obj))
     
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1, "omero.share": 2})
     assert d.copy() ==  d
     assert getHash(d.copy()) !=  getHash(d)
     assert ServiceOptsDict().copy() ==  ServiceOptsDict()
     assert getHash(ServiceOptsDict().copy()) !=  getHash(ServiceOptsDict())
     pytest.raises(TypeError, d.copy, None)
Exemplo n.º 22
0
    def test_constructor(self):
        self.assertEqual(ServiceOptsDict(), {})
        self.assert_(ServiceOptsDict() is not {})
        self.assert_(ServiceOptsDict() is not dict())
        
        d = {"omero.group":-1}
        d = ServiceOptsDict(d)
        
        resd = d.get("omero.group")
        self.assert_(isinstance(resd, str))
        self.assertEqual(d.get("omero.group"), str(d["omero.group"]))
        
        d = ServiceOptsDict(x=1,y=2)
        self.assertEqual(d.get("x"), "1")
        self.assertEqual(d.get("y"), "2")

        # ServiceOptsDict can be passed initializing data, but it needs to be a dict
        self.assertRaises(AttributeError, ServiceOptsDict, kwargs={"data":"data"})
        s = ServiceOptsDict(data={'option':'a'})
Exemplo n.º 23
0
    def test_keys(self):
        d = ServiceOptsDict()
        self.assertEqual(d.keys(), [])

        d = ServiceOptsDict({"omero.group": -1})
        k = d.keys()
        self.assert_(d.has_key('omero.group'))

        self.assertRaises(TypeError, d.keys, None)
Exemplo n.º 24
0
    def test_getitem(self):
        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        self.assertEqual(d["omero.group"], "-1")
        self.assertEqual(d["omero.user"], "1")

        d["omero.share"] = 2
        d["foo"] = "bar"
        self.assertEqual(d["omero.share"], "2")
        self.assertEqual(d["foo"], "bar")

        del d["omero.user"]

        self.assertEqual(d, {
            "omero.group": "-1",
            'foo': 'bar',
            "omero.share": "2"
        })

        self.assertRaises(TypeError, d.__getitem__)

        self.assertEqual(d.get("omero.user"), None)
        self.assertEqual(d.get("omero.user", "5"), "5")
Exemplo n.º 25
0
    def test_copy(self):
        def getHash(obj):
            return hex(id(obj))

        d = ServiceOptsDict({
            "omero.group": -1,
            "omero.user": 1,
            "omero.share": 2
        })
        self.assertEqual(d.copy(), d)
        self.assertNotEqual(getHash(d.copy()), getHash(d))
        self.assertEqual(ServiceOptsDict().copy(), ServiceOptsDict())
        self.assertNotEqual(getHash(ServiceOptsDict().copy()),
                            getHash(ServiceOptsDict()))
        self.assertRaises(TypeError, d.copy, None)
Exemplo n.º 26
0
    def test_items(self):
        d = ServiceOptsDict()
        assert d.items() ==  []

        d = ServiceOptsDict({"omero.group":-1})
        assert d.items() ==  [("omero.group", "-1")]

        pytest.raises(TypeError, d.items, None)
Exemplo n.º 27
0
    def test_items(self):
        d = ServiceOptsDict()
        self.assertEqual(d.items(), [])

        d = ServiceOptsDict({"omero.group": -1})
        self.assertEqual(d.items(), [("omero.group", "-1")])

        self.assertRaises(TypeError, d.items, None)
Exemplo n.º 28
0
    def test_values(self):
        d = ServiceOptsDict()
        self.assertEqual(d.values(), [])

        d = ServiceOptsDict({"omero.group": -1})
        self.assertEqual(d.values(), ["-1"])

        self.assertRaises(TypeError, d.values, None)

        d = ServiceOptsDict({
            "a": None,
            "b": True,
            "c": "foo",
            "d": 1,
            "e": 1.45,
            "f": [],
            "g": {}
        })
        self.assertEqual(d.values(), ['foo', '1.45', '1'])
Exemplo n.º 29
0
    def test_has_key(self):
        d = ServiceOptsDict()
        self.assert_(not d.has_key('omero'))

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        k = d.keys()
        k.sort()
        self.assertEqual(k, ['omero.group', 'omero.user'])

        self.assertRaises(TypeError, d.has_key)
Exemplo n.º 30
0
 def test_values(self):
     d = ServiceOptsDict()
     self.assertEqual(d.values(), [])
     
     d = ServiceOptsDict({"omero.group":-1})
     self.assertEqual(d.values(), ["-1"])
     
     self.assertRaises(TypeError, d.values, None)
     
     d = ServiceOptsDict({"a":None, "b":True, "c":"foo", "d":1, "e":1.45, "f":[], "g":{}})
     self.assertEqual(d.values(), ['foo', '1.45', '1'])
Exemplo n.º 31
0
    def test_setter_an_getter(self):
        group = -1
        user = 1
        share = 2

        d = ServiceOptsDict()
        d.set("omero.group", group)
        self.assertEqual(d.get("omero.group"), d.getOmeroGroup())

        d.setOmeroGroup(group)
        self.assertEqual(d.get("omero.group"), d.getOmeroGroup())

        d.set("omero.user", user)
        self.assertEqual(d.get("omero.user"), d.getOmeroUser())

        d.setOmeroUser(user)
        self.assertEqual(d.get("omero.user"), d.getOmeroUser())

        d.set("omero.share", share)
        self.assertEqual(d.get("omero.share"), d.getOmeroShare())

        d.setOmeroShare(share)
        self.assertEqual(d.get("omero.share"), d.getOmeroShare())
Exemplo n.º 32
0
 def test_repr(self):
     d = ServiceOptsDict()
     self.assertEqual(repr(d), '<ServiceOptsDict: {}>')
     d["omero.group"] = -1
     self.assertEqual(repr(d), "<ServiceOptsDict: {'omero.group': '-1'}>")
Exemplo n.º 33
0
 def test_repr(self):
     d = ServiceOptsDict()
     assert repr(d) ==  '<ServiceOptsDict: {}>'
     d["omero.group"] = -1
     assert repr(d) ==  "<ServiceOptsDict: {'omero.group': '-1'}>"
Exemplo n.º 34
0
    def test_setitem(self):

        # string
        d = ServiceOptsDict({"omero.share": "2", "omero.user": "******"})
        d["omero.group"] = "-1"

        # unicode
        d = ServiceOptsDict({"omero.share": u'2', "omero.user": u'1'})
        d["omero.group"] = u'-1'

        # int
        d = ServiceOptsDict({"omero.share": 1, "omero.user": 2})
        d["omero.group"] = -1

        # long
        import sys
        maxint = sys.maxint
        d = ServiceOptsDict({"omero.group": (maxint + 1)})
        d["omero.user"] = (maxint + 1)

        # Setter passed None as value remove from internal dict
        d = ServiceOptsDict({"omero.share": "2", "omero.user": "******"})
        self.assertNotEqual(d.get("omero.share"), None)
        d.setOmeroShare()
        self.assertEqual(d.get("omero.share"), None)
        self.assertNotEqual(d.get("omero.user"), None)
        d.setOmeroUser()
        self.assertEqual(d.get("omero.user"), None)

        try:
            d = ServiceOptsDict({"omero.group": True})
            d["omero.user"] = True
        except:
            pass
        else:
            self.fail(
                "AttributeError: ServiceOptsDict argument must be a string, unicode or numeric type"
            )

        try:
            d = ServiceOptsDict({"omero.group": []})
            d["omero.user"] = []
        except:
            pass
        else:
            self.fail(
                "AttributeError: ServiceOptsDict argument must be a string, unicode or numeric type"
            )

        try:
            d = ServiceOptsDict({"omero.group": {}})
            d["omero.user"] = {}
        except:
            pass
        else:
            self.fail(
                "AttributeError: ServiceOptsDict argument must be a string, unicode or numeric type"
            )
Exemplo n.º 35
0
 def test_len(self):
     d = ServiceOptsDict()
     assert len(d) ==  0
     
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1})
     assert len(d) ==  2
Exemplo n.º 36
0
    def test_setitem(self):
        
        # string
        d = ServiceOptsDict({"omero.share": "2","omero.user": "******"})
        d["omero.group"] = "-1"
        
        # unicode
        d = ServiceOptsDict({"omero.share": u'2',"omero.user": u'1'})
        d["omero.group"] = u'-1'
        
        # int
        d = ServiceOptsDict({"omero.share": 1,"omero.user": 2})
        d["omero.group"] = -1
        
        # long
        import sys
        maxint = sys.maxint
        d = ServiceOptsDict({"omero.group": (maxint+1)})
        d["omero.user"] = (maxint+1)

        # Setter passed None as value remove from internal dict
        d = ServiceOptsDict({"omero.share": "2","omero.user": "******"})
        assert d.get("omero.share") !=  None
        d.setOmeroShare()
        assert d.get("omero.share") ==  None
        assert d.get("omero.user") !=  None
        d.setOmeroUser()
        assert d.get("omero.user") ==  None
        
        try:
            d = ServiceOptsDict({"omero.group": True})
            d["omero.user"] = True
        except:
            pass
        else:
            self.fail("AttributeError: ServiceOptsDict argument must be a string, unicode or numeric type")
        
        try:
            d = ServiceOptsDict({"omero.group": []})
            d["omero.user"] = []
        except:
            pass
        else:
            self.fail("AttributeError: ServiceOptsDict argument must be a string, unicode or numeric type")
        
        try:
            d = ServiceOptsDict({"omero.group": {}})
            d["omero.user"] = {}
        except:
            pass
        else:
            self.fail("AttributeError: ServiceOptsDict argument must be a string, unicode or numeric type")
Exemplo n.º 37
0
    def test_constructor(self):
        assert ServiceOptsDict() ==  {}
        assert ServiceOptsDict() is not {}
        assert ServiceOptsDict() is not dict()
        
        d = {"omero.group":-1}
        d = ServiceOptsDict(d)
        
        resd = d.get("omero.group")
        assert isinstance(resd, str)
        assert d.get("omero.group") ==  str(d["omero.group"])
        
        d = ServiceOptsDict(x=1,y=2)
        assert d.get("x") ==  "1"
        assert d.get("y") ==  "2"

        # ServiceOptsDict can be passed initializing data, but it needs to be a dict
        pytest.raises(AttributeError, ServiceOptsDict, kwargs={"data":"data"})
        s = ServiceOptsDict(data={'option':'a'})
Exemplo n.º 38
0
    def test_constructor(self):
        self.assertEqual(ServiceOptsDict(), {})
        self.assert_(ServiceOptsDict() is not {})
        self.assert_(ServiceOptsDict() is not dict())

        d = {"omero.group": -1}
        d = ServiceOptsDict(d)

        resd = d.get("omero.group")
        self.assert_(isinstance(resd, str))
        self.assertEqual(d.get("omero.group"), str(d["omero.group"]))

        d = ServiceOptsDict(x=1, y=2)
        self.assertEqual(d.get("x"), "1")
        self.assertEqual(d.get("y"), "2")

        # ServiceOptsDict can be passed initializing data, but it needs to be a dict
        self.assertRaises(AttributeError,
                          ServiceOptsDict,
                          kwargs={"data": "data"})
        s = ServiceOptsDict(data={'option': 'a'})
Exemplo n.º 39
0
 def test_clear(self):
     d = ServiceOptsDict({"omero.group":-1, "omero.user": 1, "omero.share": 2})
     d.clear()
     self.assertEqual(d, {})
     
     self.assertRaises(TypeError, d.clear, None)
Exemplo n.º 40
0
    def test_len(self):
        d = ServiceOptsDict()
        self.assertEqual(len(d), 0)

        d = ServiceOptsDict({"omero.group": -1, "omero.user": 1})
        self.assertEqual(len(d), 2)
Exemplo n.º 41
0
 def test_setter_an_getter(self):
     group = -1
     user = 1
     share = 2
     
     d = ServiceOptsDict()
     d.set("omero.group", group)
     assert d.get("omero.group") ==  d.getOmeroGroup()
     
     d.setOmeroGroup(group)
     assert d.get("omero.group") ==  d.getOmeroGroup()
     
     d.set("omero.user", user)
     assert d.get("omero.user") ==  d.getOmeroUser()
     
     d.setOmeroUser(user)
     assert d.get("omero.user") ==  d.getOmeroUser()
     
     d.set("omero.share", share)
     assert d.get("omero.share") ==  d.getOmeroShare()
     
     d.setOmeroShare(share)
     assert d.get("omero.share") ==  d.getOmeroShare()