Full rich comparison operators
[pyderasn.git] / tests / test_pyderasn.py
index 0be393ed20841fc480345332e1864a6788ac9720..58ecbdb52d3a132cdb0edae0d6085155eaac0cfc 100644 (file)
@@ -372,10 +372,12 @@ class TestBoolean(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == bool(obj2), value1 == value2)
             obj1 = klass(value1, impl=tag1)
             obj2 = klass(value1, impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(data_strategy())
     def test_call(self, d):
@@ -677,10 +679,12 @@ class TestInteger(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == int(obj2), value1 == value2)
             obj1 = klass(value1, impl=tag1)
             obj2 = klass(value1, impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(lists(integers()))
     def test_sorted_works(self, values):
@@ -1129,10 +1133,12 @@ class TestBitString(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == bytes(obj2), value1[1] == value2[1])
             obj1 = klass(value1, impl=tag1)
             obj2 = klass(value1, impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(data_strategy())
     def test_call(self, d):
@@ -1434,10 +1440,19 @@ class TestOctetString(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == bytes(obj2), value1 == value2)
             obj1 = klass(value1, impl=tag1)
             obj2 = klass(value1, impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
+
+    @given(lists(binary()))
+    def test_sorted_works(self, values):
+        self.assertSequenceEqual(
+            [bytes(v) for v in sorted(OctetString(v) for v in values)],
+            sorted(values),
+        )
 
     @given(data_strategy())
     def test_bounds_satisfied(self, d):
@@ -1698,6 +1713,7 @@ class TestNull(CommonMixin, TestCase):
             obj1 = klass(impl=tag1)
             obj2 = klass(impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
             self.assertNotEqual(obj1, tag2)
 
     @given(data_strategy())
@@ -1910,11 +1926,13 @@ class TestObjectIdentifier(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == tuple(obj2), value1 == value2)
             self.assertEqual(str(obj1) == str(obj2), value1 == value2)
             obj1 = klass(value1, impl=tag1)
             obj2 = klass(value1, impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(lists(oid_strategy()))
     def test_sorted_works(self, values):
@@ -2272,10 +2290,12 @@ class TestEnumerated(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == int(obj2), value1 == value2)
             obj1 = klass(value1, impl=tag1)
             obj2 = klass(value1, impl=tag2)
             self.assertEqual(obj1 == obj2, tag1 == tag2)
+            self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(data_strategy())
     def test_call(self, d):
@@ -2486,11 +2506,13 @@ class StringMixin(object):
         obj1 = self.base_klass(value1)
         obj2 = self.base_klass(value2)
         self.assertEqual(obj1 == obj2, value1 == value2)
+        self.assertEqual(obj1 != obj2, value1 != value2)
         self.assertEqual(obj1 == bytes(obj2), value1 == value2)
         self.assertEqual(obj1 == text_type(obj2), value1 == value2)
         obj1 = self.base_klass(value1, impl=tag1)
         obj2 = self.base_klass(value1, impl=tag2)
         self.assertEqual(obj1 == obj2, tag1 == tag2)
+        self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(data_strategy())
     def test_bounds_satisfied(self, d):
@@ -2846,11 +2868,13 @@ class TimeMixin(object):
         obj1 = self.base_klass(value1)
         obj2 = self.base_klass(value2)
         self.assertEqual(obj1 == obj2, value1 == value2)
+        self.assertEqual(obj1 != obj2, value1 != value2)
         self.assertEqual(obj1 == obj2.todatetime(), value1 == value2)
         self.assertEqual(obj1 == bytes(obj2), value1 == value2)
         obj1 = self.base_klass(value1, impl=tag1)
         obj2 = self.base_klass(value1, impl=tag2)
         self.assertEqual(obj1 == obj2, tag1 == tag2)
+        self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(data_strategy())
     def test_call(self, d):
@@ -3173,6 +3197,7 @@ class TestAny(CommonMixin, TestCase):
             obj1 = klass(value1)
             obj2 = klass(value2)
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == bytes(obj2), value1 == value2)
 
     @given(data_strategy())
@@ -3412,6 +3437,7 @@ class TestChoice(CommonMixin, TestCase):
             obj1 = klass(("whatever", Boolean(value1)))
             obj2 = klass(("whatever", Boolean(value2)))
             self.assertEqual(obj1 == obj2, value1 == value2)
+            self.assertEqual(obj1 != obj2, value1 != value2)
             self.assertEqual(obj1 == obj2._value, value1 == value2)
             self.assertFalse(obj1 == obj2._value[1])
 
@@ -4270,11 +4296,13 @@ class SeqOfMixing(object):
         obj1 = SeqOf([Boolean(value1)])
         obj2 = SeqOf([Boolean(value2)])
         self.assertEqual(obj1 == obj2, value1 == value2)
+        self.assertEqual(obj1 != obj2, value1 != value2)
         self.assertEqual(obj1 == list(obj2), value1 == value2)
         self.assertEqual(obj1 == tuple(obj2), value1 == value2)
         obj1 = SeqOf([Boolean(value1)], impl=tag1)
         obj2 = SeqOf([Boolean(value1)], impl=tag2)
         self.assertEqual(obj1 == obj2, tag1 == tag2)
+        self.assertEqual(obj1 != obj2, tag1 != tag2)
 
     @given(lists(booleans()))
     def test_iter(self, values):