예제 #1
0
    def test_atexit(self):
        # http://bugs.python.org/issue25532
        from testfixtures.mock import call

        m = Mock()
        with Replacer() as r:
            # make sure the marker is false, other tests will
            # probably have set it
            r.replace('testfixtures.TempDirectory.atexit_setup', False)
            r.replace('atexit.register', m.register)

            d = TempDirectory()

            expected = [call.register(d.atexit)]

            compare(expected, m.mock_calls)

            with catch_warnings(record=True) as w:
                d.atexit()
                self.assertTrue(len(w), 1)
                compare(str(w[0].message), (  # pragma: no branch
                    "TempDirectory instances not cleaned up by shutdown:\n" +
                    d.path
                    ))

            d.cleanup()

            compare(set(), TempDirectory.instances)

            # check re-running has no ill effects
            d.atexit()
 def test_atexit(self):
     d = TempDirectory()
     self.assertTrue(TempDirectory.atexit in [t[0] for t in atexit._exithandlers])
     with catch_warnings(record=True) as w:
         d.atexit()
         self.assertTrue(len(w), 1)
         compare(str(w[0].message), ("TempDirectory instances not cleaned up by shutdown:\n" + d.path))
     d.cleanup()
     # call again to make sure nothing blows up:
     d.atexit()
예제 #3
0
 def test_atexit(self):
     from mock import call
     m = Mock()
     with Replacer() as r:
         r.replace('testfixtures.TempDirectory.atexit_setup', False)
         r.replace('atexit.register', m.register)
         d = TempDirectory()
         expected = [call.register(d.atexit)]
         compare(expected, m.mock_calls)
         with catch_warnings(record=True) as w:
             d.atexit()
             self.assertTrue(len(w), 1)
             compare(str(w[0].message), 'TempDirectory instances not cleaned up by shutdown:\n' + d.path)
         d.cleanup()
         compare(set(), TempDirectory.instances)
         d.atexit()