Esempio n. 1
0
 def testSorting(self):
     m1 = MACAddress(bytearray([0x48, 0x45, 0xff, 0xff, 0xff, 0xfe]))
     m2 = MACAddress(bytearray([0x48, 0x45, 0x00, 0x00, 0x02, 0x2e]))
     m3 = MACAddress(bytearray([0x48, 0x44, 0x00, 0x00, 0x02, 0x2e]))
     m4 = MACAddress(bytearray([0x48, 0x46, 0x00, 0x00, 0x02, 0x2e]))
     macs = sorted([m1, m2, None, m3, m4])
     self.assertEqual([None, m3, m2, m1, m4], macs)
     allNotEqual(self, macs)
     allHashNotEqual(self, macs)
Esempio n. 2
0
    def testCmp(self):
        self.assertEqual(TestState.PASSED, TestState.PASSED)

        states = sorted([
            TestState.PASSED, TestState.FAILED, TestState.BROKEN,
            TestState.NOT_RUN
        ])
        self.assertEqual(states, [
            TestState.BROKEN, TestState.FAILED, TestState.NOT_RUN,
            TestState.PASSED
        ])
        allNotEqual(self, states)
        allHashNotEqual(self, states)
Esempio n. 3
0
  def testUniverse(self):
    # universe doesn't have hash and implements eq and < only on id
    a = Universe(1, 2, Universe.LTP, [1, 2], [3, 4])
    aeq = Universe(1, 3, Universe.HTP, [1, 2, 3], [3, 4, 5])
    b = Universe(2, 2, Universe.LTP, [1, 2], [3, 4])
    c = Universe(3, 2, Universe.HTP, [1, 2], [3, 4])

    self.assertEqual(a, aeq)
    allNotEqual(self, [a, b, c])

    s = sorted([c, b, a])
    self.assertEqual([a, b, c], s)

    self.assertEqual(a.__lt__("hello"), NotImplemented)
    self.assertNotEqual(a, "hello")
Esempio n. 4
0
  def testDevice(self):
    # only eq on alias (2)
    a = Device(1, 2, "a", 4, [1, 2], [3, 4])
    aeq = Device(0, 2, "za", 54, [0, 1, 2, 3], [2, 3, 4])
    b = Device(2, 3, "b", 4, [1, 2], [3, 4])
    c = Device(2, 4, "b", 4, [1, 2], [3, 4])

    self.assertEqual(a, aeq)
    allNotEqual(self, [a, b, c])

    s = sorted([b, a, c])
    self.assertEqual([a, b, c], s)

    self.assertEqual(a.__lt__("hello"), NotImplemented)
    self.assertNotEqual(a, "hello")
Esempio n. 5
0
  def testSort(self):
    store = PidStore.PidStore()
    store.Load([os.path.join(path, "test_pids.proto")])

    self.assertEqual(len(store.Pids()), 70)
    pids = [p.value for p in sorted(store.Pids())]
    self.assertEqual(pids,
                     [16, 17, 21, 32, 48, 49, 50, 51, 80, 81, 96, 112, 128,
                      129, 130, 144, 160, 176, 192, 193, 194, 224, 225, 240,
                      288, 289, 290, 512, 513, 514, 1024, 1025, 1026, 1027,
                      1028, 1029, 1280, 1281, 1536, 1537, 1538, 1539, 4096,
                      4097, 4112, 4128, 4129, 4144, 4145, 32688, 32689, 32690,
                      32691, 32692, 32752, 32753, 32754, 32755, 32756, 32757,
                      32758, 32759, 32760, 32761, 32762, 32763, 32764, 32765,
                      32766, 32767])
    allNotEqual(self, store.Pids())
    allHashNotEqual(self, store.Pids())
Esempio n. 6
0
  def testRDMNack(self):
    # hash and eq only on value (1)
    a = RDMNack(1, "a")
    aeq = RDMNack(1, "also a")
    b = RDMNack(2, "b")
    c = RDMNack(3, "c")

    self.assertEqual(a, aeq)
    self.assertEqual(hash(a), hash(aeq))
    allNotEqual(self, [a, b, c])
    allHashNotEqual(self, [a, b, c])

    s = sorted([c, a, b])
    self.assertEqual([a, b, c], s)

    self.assertEqual(a.__lt__("hello"), NotImplemented)
    self.assertNotEqual(a, "hello")
Esempio n. 7
0
  def testPort(self):
    # hash and eq only on id (1)
    a = Port(1, 1, False, "a", False)
    aeq = Port(1, 2, True, "xa", True)
    b = Port(2, 2, False, "b", False)
    c = Port(3, 3, False, "b", False)

    self.assertEqual(a, aeq)
    self.assertEqual(hash(a), hash(aeq))
    allNotEqual(self, [a, b, c])
    allHashNotEqual(self, [a, b, c])

    s = sorted([c, a, b])
    self.assertEqual([a, b, c], s)

    self.assertEqual(a.__lt__("hello"), NotImplemented)
    self.assertNotEqual(a, "hello")
Esempio n. 8
0
    def testCmp(self):
        u2 = UID(0x4845, 0x0000022e)
        u3 = UID(0x4844, 0x0000022e)
        u3a = UID(0x4844, 0x0000022e)
        u4 = UID(0x4844, 0x00000230)

        self.assertEqual(u3, u3a)
        self.assertEqual(hash(u3), hash(u3a))
        self.assertTrue(u3 <= u3a)
        self.assertTrue(u3 >= u3a)

        self.assertTrue(u3 < u2)
        self.assertTrue(u2 > u3)
        self.assertTrue(u3 <= u2)
        self.assertTrue(u2 >= u3)
        self.assertTrue(u3 != u2)

        self.assertFalse(u3 > u2)
        self.assertFalse(u2 < u3)
        self.assertFalse(u3 >= u2)
        self.assertFalse(u2 <= u3)
        self.assertFalse(u3 == u2)

        self.assertNotEqual(u3, u4)
        self.assertNotEqual(hash(u3), hash(u4))
        self.assertFalse(u3 == u4)
        self.assertTrue(u3 < u4)
        self.assertFalse(u4 < u3)

        self.assertEqual(u2.__lt__("hello"), NotImplemented)
        self.assertNotEqual(u2, "hello")

        # None case
        self.assertFalse(u3 < None)
        self.assertTrue(u3 > None)
        self.assertFalse(u3 <= None)
        self.assertTrue(u3 >= None)
        self.assertTrue(u3 is not None)
        self.assertFalse(u3 is None)

        allNotEqual(self, [u2, u3, u4])
        allHashNotEqual(self, [u2, u3, u4])