Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
 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)
Пример #6
0
 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)
Пример #7
0
 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)
Пример #8
0
 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)
Пример #9
0
 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))
Пример #10
0
 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)
Пример #11
0
 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))
Пример #12
0
 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)