示例#1
0
    def test_greater_equal(self):
        self.assertGreaterEqual(1, Values(1, "1"))
        self.assertGreaterEqual(2, Values(1, "A"))
        self.assertGreaterEqual(Values(2, "A"), Values(1, "A"))

        with self.assertRaises(NotImplementedError):
            self.assertGreaterEqual("", Values(1, "1"))
示例#2
0
    def test_less_equal(self):
        self.assertLessEqual(0, Values(1, "A"))
        self.assertLessEqual(1, Values(1, "A"))
        self.assertLessEqual(Values(1, "A"), Values(1, "A"))

        with self.assertRaises(NotImplementedError):
            self.assertLessEqual("", Values(1, "A"))
示例#3
0
    def test_cast_enum(self):
        Values.check_uniqueness = False
        e = Enum("e", A=Values(-4242, "A"))
        self.assertEqual(e.A.int, -4242)
        self.assertEqual(e.A.str, "A")
        s = cast_enum(e, str)
        self.assertEqual(s.A, "A")
        i = cast_enum(e, int)
        self.assertEqual(i.A, -4242)
        self.assertEqual(i._map, {"A": -4242, -4242: "A"})

        with self.assertRaises(TypeError):
            cast_enum(e, None)
示例#4
0
 def test_convert_str(self):
     self.assertEqual(str(Values(1, "A")), "A")
示例#5
0
 def test_convert_int(self):
     self.assertEqual(int(Values(1, "A")), 1)
示例#6
0
 def test_contains(self):
     self.assertIn(1, Values(1, "A"))
     self.assertIn("A", Values(1, "A"))
     self.assertIn(Values(1, "A"), Values(1, "A"))
示例#7
0
    def test_less(self):
        self.assertLess(0, Values(1, "A"))
        self.assertLess(Values(0, "A"), Values(1, "A"))

        with self.assertRaises(NotImplementedError):
            self.assertLess("", Values(1, "A"))
示例#8
0
    def test_greater(self):
        self.assertGreater(2, Values(1, "A"))
        self.assertGreater(Values(2, "A"), Values(1, "A"))

        with self.assertRaises(NotImplementedError):
            self.assertGreater("", Values(1, "A"))
示例#9
0
 def test_not_equal(self):
     self.assertNotEqual(Values(1, "A"), Values(2, "B"))
     self.assertNotEqual(Values(1, "A"), "B")
     self.assertNotEqual(Values(1, "A"), 2)
示例#10
0
 def test_equal(self):
     self.assertEqual(Values(1, "A"), Values(1, "A"))
     self.assertEqual(Values(1, "A"), "A")
     self.assertEqual(Values(1, "A"), 1)
示例#11
0
 def test_unique_values(self):
     Values(1, "A")
     Values.check_uniqueness = True
     with self.assertRaises(ValueError):
         Values(1, "A")
示例#12
0
    def test_input_types(self):
        with self.assertRaises(TypeError):
            Values(int="foo", str="foo")

        with self.assertRaises(TypeError):
            Values(int=1, str=1)
示例#13
0
 def test_hash(self):
     v = Values(int=1, str="foo")
     self.assertEqual(hash(v), hash(v.str))
示例#14
0
 def test_dump_enum_value(self):
     self.assertEqual(
         loads(dumps({"data": Values(1, "A")})),
         loads(dumps({"data": "A"})))