def test_cmp(self): # Equality ava1 = AVA(self.attr1, self.value1) assert ava1 == self.ava1 assert ava1 == self.ava1 assert ava1 == self.str_ava1 assert ava1 == self.str_ava1 result = cmp(ava1, self.ava1) assert result == 0 # Upper case attr should still be equal ava1 = AVA(self.attr1.upper(), self.value1) assert ava1.attr != self.attr1 assert ava1.value == self.value1 assert ava1 == self.ava1 assert ava1 == self.ava1 result = cmp(ava1, self.ava1) assert result == 0 # Upper case value should still be equal ava1 = AVA(self.attr1, self.value1.upper()) assert ava1.attr == self.attr1 assert ava1.value != self.value1 assert ava1 == self.ava1 assert ava1 == self.ava1 result = cmp(ava1, self.ava1) assert result == 0 # Make ava1's attr greater with pytest.raises(AttributeError): ava1.attr = self.attr1 + "1" ava1 = AVA(self.attr1 + "1", self.value1.upper()) assert ava1 != self.ava1 assert ava1 != self.ava1 result = cmp(ava1, self.ava1) assert result == 1 result = cmp(self.ava1, ava1) assert result == -1 # Reset ava1's attr, should be equal again with pytest.raises(AttributeError): ava1.attr = self.attr1 ava1 = AVA(self.attr1, self.value1.upper()) result = cmp(ava1, self.ava1) assert result == 0 # Make ava1's value greater # attr will be equal, this tests secondary comparision component with pytest.raises(AttributeError): ava1.value = self.value1 + "1" ava1 = AVA(self.attr1, self.value1 + "1") result = cmp(ava1, self.ava1) assert result == 1 result = cmp(self.ava1, ava1) assert result == -1
def test_cmp(self): # Equality ava1 = AVA(self.attr1, self.value1) self.assertTrue(ava1 == self.ava1) self.assertFalse(ava1 != self.ava1) self.assertTrue(ava1 == self.str_ava1) self.assertFalse(ava1 != self.str_ava1) result = cmp(ava1, self.ava1) self.assertEqual(result, 0) # Upper case attr should still be equal ava1 = AVA(self.attr1.upper(), self.value1) self.assertFalse(ava1.attr == self.attr1) self.assertTrue(ava1.value == self.value1) self.assertTrue(ava1 == self.ava1) self.assertFalse(ava1 != self.ava1) result = cmp(ava1, self.ava1) self.assertEqual(result, 0) # Upper case value should still be equal ava1 = AVA(self.attr1, self.value1.upper()) self.assertTrue(ava1.attr == self.attr1) self.assertFalse(ava1.value == self.value1) self.assertTrue(ava1 == self.ava1) self.assertFalse(ava1 != self.ava1) result = cmp(ava1, self.ava1) self.assertEqual(result, 0) # Make ava1's attr greater with self.assertRaises(AttributeError): ava1.attr = self.attr1 + "1" ava1 = AVA(self.attr1 + "1", self.value1.upper()) self.assertFalse(ava1 == self.ava1) self.assertTrue(ava1 != self.ava1) result = cmp(ava1, self.ava1) self.assertEqual(result, 1) result = cmp(self.ava1, ava1) self.assertEqual(result, -1) # Reset ava1's attr, should be equal again with self.assertRaises(AttributeError): ava1.attr = self.attr1 ava1 = AVA(self.attr1, self.value1.upper()) result = cmp(ava1, self.ava1) self.assertEqual(result, 0) # Make ava1's value greater # attr will be equal, this tests secondary comparision component with self.assertRaises(AttributeError): ava1.value = self.value1 + "1" ava1 = AVA(self.attr1, self.value1 + "1") result = cmp(ava1, self.ava1) self.assertEqual(result, 1) result = cmp(self.ava1, ava1) self.assertEqual(result, -1)