Skip to content

Instantly share code, notes, and snippets.

@bChiquet
Created February 19, 2017 08:19
Show Gist options
  • Save bChiquet/bc4d68fc2961a6639423e1270bb80fca to your computer and use it in GitHub Desktop.
Save bChiquet/bc4d68fc2961a6639423e1270bb80fca to your computer and use it in GitHub Desktop.
from unittest import TestCase
class Anything:
def __eq__(self, other):
return True
def __ne__(self, other):
return False
def __hash__(self):
class __AnyInt(int):
def __eq__(self, other):
return True
def __ne__(self, other):
return False
return __AnyInt()
class EventsTest(TestCase):
def test__anyInt_matches_any_int(self):
self.assertFalse(Anything() is Anything())
self.assertEqual(Anything().__hash__(), 2)
self.assertEqual(Anything().__hash__(), 3)
self.assertTrue(isinstance(Anything().__hash__(), int))
self.assertTrue(isinstance(self.__hash__(), int))
self.assertEqual("two", Anything())
self.assertEqual("two".__hash__(), Anything().__hash__())
def test_sets_containing_underscores(self):
self.assertIn("two", [Anything()])
self.assertIn("two", {Anything()})
self.assertEqual({"one", "two"}, {"one", Anything()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment