def test_str(self, lib): _lib = Mock() _lib.GLib.Variant.side_effect = Mock(side_effect=variant) lib.return_value = _lib # str s = 'hello' tag, value = Variant.str(s) self.assertEqual(tag, 's') self.assertEqual(value, s) # none self.assertTrue(Variant.str(None) is None)
def test_str_list(self, lib): _lib = Mock() _lib.GLib.Variant.side_effect = Mock(side_effect=variant) lib.return_value = _lib # list _list = ['1', '2'] tag, value = Variant.str_list(_list) self.assertEqual(tag, 'as') self.assertEqual(value, tuple(_list)) # none self.assertTrue(Variant.str_list(None) is None)
def test_int(self, lib): _lib = Mock() _lib.GLib.Variant.side_effect = Mock(side_effect=variant) lib.return_value = _lib # integer n = '10' tag, value = Variant.int(n) self.assertEqual(tag, 'i') self.assertEqual(value, int(n)) # none self.assertTrue(Variant.int(None) is None)
def test_bool(self, lib): _lib = Mock() _lib.GLib.Variant.side_effect = Mock(side_effect=variant) lib.return_value = _lib # bool b = True tag, value = Variant.bool(b) self.assertEqual(tag, 's') self.assertEqual(value, 'true') # negated b = True tag, value = Variant.bool(b, negated=True) self.assertEqual(tag, 's') self.assertEqual(value, 'false') # none self.assertTrue(Variant.bool(None) is None)
def test_options(self, lib): _lib = Mock() _lib.GLib.Variant.side_effect = Mock(side_effect=variant) lib.return_value = _lib d = dict(a=1, b=2, c=3) tag, value = Variant.dict(d) self.assertEqual(tag, 'a{sv}') self.assertEqual(value, dict((k, v) for k, v in d.iteritems() if v))
def test_dict(self, lib): _lib = Mock() _lib.GLib.Variant.side_effect = Mock(side_effect=variant) lib.return_value = _lib d = dict(a=1, b=2) tag, value = Variant.dict(d) self.assertEqual(tag, 'a{sv}') self.assertEqual(value, d)