Exemplo n.º 1
0
    def test_something_typeConversions(self):
        import math

        self.assertEqual(complex(1), complex(Something(1)))
        self.assertEqual(oct(1), oct(Something(1)))
        self.assertEqual(hex(16), hex(Something(16)))
        self.assertEqual(math.trunc(math.pi), math.trunc(maybe(math.pi)))
Exemplo n.º 2
0
 def test_nothing_cmp(self):
     if PY2:
         self.assertEqual(0, cmp(Nothing(), Nothing()))
         self.assertEqual(1, cmp(1, Nothing()))
         self.assertEqual(1, cmp(Something(5), Nothing()))
         self.assertEqual(1, cmp(5, Nothing()))
         self.assertEqual(-1, cmp(Nothing(), Something(5)))
         self.assertEqual(-1, cmp(Nothing(), 5))
Exemplo n.º 3
0
    def test_something_cmp_handlesComparisonBetweenSomethings(self):
        l = [Something(10), Something(3)]
        sortedl = sorted(l)
        self.assertTrue(isinstance(sortedl[0], Something))
        self.assertTrue(isinstance(sortedl[1], Something))

        self.assertEqual(sortedl[0], 3)
        self.assertEqual(sortedl[1], 10)
Exemplo n.º 4
0
    def test_comparisons(self):
        self.assertReallyEqual(Something(1), 1)
        self.assertReallyEqual(1, Something(1))
        self.assertReallyEqual(Something(1), Something(1))
        self.assertReallyEqual(Nothing(), Nothing())

        self.assertReallyNotEqual(Something(1), Something(2))
        self.assertReallyNotEqual(Something(1), Nothing())
        self.assertReallyNotEqual(Nothing(), Something(1))
Exemplo n.º 5
0
    def test_something_cmp(self):
        l = [Something(1), 2, Nothing()]
        sortedl = sorted(l)
        self.assertTrue(isinstance(sortedl[0], Nothing))
        self.assertTrue(isinstance(sortedl[1], Something))
        self.assertTrue(isinstance(sortedl[2], int))

        self.assertEqual(sortedl[0], None)
        self.assertEqual(sortedl[1], 1)
        self.assertEqual(sortedl[2], 2)
Exemplo n.º 6
0
    def test_something_conversions(self):
        s = "value"
        d = dict(name="Eran")
        n = 123
        f = 3.14

        if PY2:
            self.assertEqual(unicode(Something(s)), s)

            self.assertEqual(long(Something(n)), n)
            self.assertIsInstance(long(Something(f)), long)

        self.assertEqual(str(Something(s)), "Something(%s)" % s)

        self.assertEqual(repr(Something(s)), "Something(%s)" % repr(s))
        self.assertEqual(repr(Something(d)), "Something(%s)" % repr(d))

        self.assertEqual(int(Something(n)), n)
        self.assertIsInstance(int(Something(n)), int)

        self.assertEqual(float(Something(f)), f)
        self.assertIsInstance(float(Something(f)), float)
Exemplo n.º 7
0
 def test_nothing_ltSomething_isTrue(self):
     self.assertTrue(Nothing() < Something(1))
Exemplo n.º 8
0
 def test_nothing_neSomething(self):
     self.assertTrue(Nothing() != Something(2))
     self.assertTrue(Something(1) != Nothing())
Exemplo n.º 9
0
 def test_nothing_notEqualToSomething(self):
     self.assertFalse(Nothing() == Something(2))
     self.assertFalse(Something(1) == Nothing())
Exemplo n.º 10
0
 def test_something_cmp_greaterThanNothing(self):
     l = [Something(0), Nothing()]
     sortedl = sorted(l)
     self.assertTrue(isinstance(sortedl[0], Nothing))
     self.assertTrue(isinstance(sortedl[1], Something))
Exemplo n.º 11
0
 def test_something_geValue_comparesTheUnderlyingValue(self):
     self.assertTrue(Something(11) > 2)
     self.assertFalse(Something(1) > 2)
Exemplo n.º 12
0
 def test_something_geSomething_comparesTheUnderlyingValue(self):
     self.assertTrue(Something(11) > Something(2))
     self.assertTrue(Something(11) >= Something(2))
     self.assertTrue(Something(11) >= Something(11))
     self.assertFalse(Something(1) > Something(2))
Exemplo n.º 13
0
 def test_something_geNothing_isTrue(self):
     self.assertTrue(Something("value") >= Nothing())
Exemplo n.º 14
0
 def test_something_leNothing_isFalse(self):
     self.assertFalse(Something("value") <= Nothing())
Exemplo n.º 15
0
 def test_something_ltSomething_usesValue(self):
     self.assertFalse(Something(3) < Something(1))
     self.assertTrue(Something(3) > Something(1))
Exemplo n.º 16
0
 def test_nothing_gtAnything_isFalse(self):
     self.assertFalse(Nothing() > Nothing())
     self.assertFalse(Nothing() > Something(123))
     self.assertFalse(Nothing() > None)
     self.assertFalse(Nothing() > "Value")
Exemplo n.º 17
0
 def test_nothing_leAnything_isTrue(self):
     self.assertTrue(Nothing() <= Nothing())
     self.assertTrue(Nothing() <= Something(123))
     self.assertTrue(Nothing() <= None)
     self.assertTrue(Nothing() <= "Value")
Exemplo n.º 18
0
 def test_nothing_geNotNoneOrNothing_isFalse(self):
     self.assertFalse(Nothing() >= Something(2))
     self.assertFalse(Nothing() >= "some")