Ticket #6350: assertIs.patch

File assertIs.patch, 5.1 KB (added by Julian Berman, 9 years ago)
  • new file twisted/topfiles/6350.feature

    diff --git a/twisted/topfiles/6350.feature b/twisted/topfiles/6350.feature
    new file mode 100644
    index 0000000..7d19d43
    - +  
     1trial test cases now support assertIs, assertIsNot, assertIsNone, and assertIsNotNone.
  • twisted/trial/_synctest.py

    diff --git a/twisted/trial/_synctest.py b/twisted/trial/_synctest.py
    index 45708eb..ef534ce 100644
    a b class _Assertions(pyunit.TestCase, object): 
    358358    failUnlessEqual = failUnlessEquals = assertEquals = assertEqual
    359359
    360360
    361     def assertIdentical(self, first, second, msg=None):
     361    def assertIs(self, first, second, msg=None):
    362362        """
    363363        Fail the test if C{first} is not C{second}.  This is an
    364364        obect-identity-equality test, not an object equality
    class _Assertions(pyunit.TestCase, object): 
    370370        if first is not second:
    371371            raise self.failureException(msg or '%r is not %r' % (first, second))
    372372        return first
    373     failUnlessIdentical = assertIdentical
     373    failUnlessIdentical = assertIdentical = assertIs
    374374
    375375
    376     def assertNotIdentical(self, first, second, msg=None):
     376    def assertIsNot(self, first, second, msg=None):
    377377        """
    378378        Fail the test if C{first} is C{second}.  This is an
    379379        obect-identity-equality test, not an object equality
    class _Assertions(pyunit.TestCase, object): 
    385385        if first is second:
    386386            raise self.failureException(msg or '%r is %r' % (first, second))
    387387        return first
    388     failIfIdentical = assertNotIdentical
     388    failIfIdentical = assertNotIdentical = assertIsNot
     389
     390
     391    def assertIsNone(self, thing, msg=None):
     392        """
     393        Assert that C{thing} is None.
     394
     395        This is an obect-identity-equality test, not an object equality
     396        (i.e. C{__eq__}) test.
     397
     398        @param msg: if msg is None, then the failure message will be
     399        '%r is not None' % (thing,)
     400        """
     401        self.assertIs(thing, None, msg=msg)
     402
     403
     404    def assertIsNotNone(self, thing, msg=None):
     405        """
     406        Assert that C{thing} is not None.
     407
     408        This is an obect-identity-equality test, not an object equality
     409        (i.e. C{__eq__}) test.
     410
     411        @param msg: if msg is None, then the failure message will be
     412        'unexpectedly None'
     413        """
     414        if msg is None:
     415            msg = "unexpectedly None"
     416        self.assertIsNot(thing, None, msg=msg)
    389417
    390418
    391419    def assertNotEqual(self, first, second, msg=None):
  • twisted/trial/test/test_assertions.py

    diff --git a/twisted/trial/test/test_assertions.py b/twisted/trial/test/test_assertions.py
    index 788cee0..047ce46 100644
    a b class TestSynchronousAssertions(unittest.SynchronousTestCase): 
    507507                              self.failIfSubstring, x, z)
    508508
    509509
     510    def test_assertIs(self):
     511        """
     512        Test a true condition of L{assertIs}.
     513        """
     514        a = object()
     515        self.assertIs(a, a)
     516
     517
     518    def test_assertIsError(self):
     519        """
     520        Test an error with L{assertIs}.
     521        """
     522        a, b = object(), object()
     523        self.assertRaises(self.failureException, self.assertIs, a, b)
     524
     525
     526    def test_assertIsNot(self):
     527        """
     528        Test a true condition of L{assertIsNot}.
     529        """
     530        a, b = object(), object()
     531        self.assertIsNot(a, b)
     532
     533
     534    def test_assertIsNotError(self):
     535        """
     536        Test an error with L{assertIsNot}.
     537        """
     538        a = object()
     539        self.assertRaises(self.failureException, self.assertIsNot, a, a)
     540
     541
     542    def test_assertIsNone(self):
     543        """
     544        Test a true condition of L{assertIsNone}.
     545        """
     546        self.assertIsNone(None)
     547
     548
     549    def test_assertIsNoneError(self):
     550        """
     551        Test an error with L{assertIsNone}.
     552        """
     553        exc = self.assertRaises(self.failureException, self.assertIsNone, True)
     554        self.assertEqual(str(exc), "%r is not None" % (True,))
     555
     556
     557    def test_assertIsNoneCustomMessage(self):
     558        """
     559        Test the default message of L{assertIsNone}.
     560        """
     561        exc = self.assertRaises(
     562            self.failureException, self.assertIsNone, True, msg="Hello")
     563        self.assertEqual(str(exc), "Hello")
     564
     565
     566    def test_assertIsNotNone(self):
     567        """
     568        Test a true condition of L{assertIsNotNone}.
     569        """
     570        self.assertIsNotNone(False)
     571
     572
     573    def test_assertIsNotNoneError(self):
     574        """
     575        Test an error with L{assertIsNotNone}.
     576        """
     577        exc = self.assertRaises(
     578            self.failureException, self.assertIsNotNone, None)
     579        self.assertEqual(str(exc), "unexpectedly None")
     580
     581
     582    def test_assertIsNotNoneCustomMessage(self):
     583        """
     584        Test the default message of L{assertIsNotNone}.
     585        """
     586        exc = self.assertRaises(
     587            self.failureException, self.assertIsNotNone, None, msg="Hello")
     588        self.assertEqual(str(exc), "Hello")
     589
     590
    510591    def test_assertIsInstance(self):
    511592        """
    512593        Test a true condition of assertIsInstance.