from __future__ import print_function

import unittest

import wrapt

class TestPostImportHooks(unittest.TestCase):

    def test_simple(self):
        invoked = []

        @wrapt.when_imported('socket')
        def hook_socket(module):
            self.assertEqual(module.__name__, 'socket')
            invoked.append(1)

        self.assertEqual(len(invoked), 0)

        import socket

        self.assertEqual(len(invoked), 1)

if __name__ == '__main__':
    unittest.main()

from __future__ import print_function

import unittest

import wrapt

class TestPostImportHooks(unittest.TestCase):

    def test_simple(self):
        invoked = []

        @wrapt.when_imported('this')
        def hook_this(module):
            self.assertEqual(module.__name__, 'this')
            invoked.append(1)

        self.assertEqual(len(invoked), 0)

        import this

        self.assertEqual(len(invoked), 1)

if __name__ == '__main__':
    unittest.main()

Adjust test to use different module as socket imported by coverage tools.
Adjust test to use different module as socket imported by coverage tools.

  from __future__ import print_function
  
  import unittest
  
  import wrapt
  
  class TestPostImportHooks(unittest.TestCase):
  
      def test_simple(self):
          invoked = []
  
-         @wrapt.when_imported('socket')
+         @wrapt.when_imported('this')
-         def hook_socket(module):
+         def hook_this(module):
-             self.assertEqual(module.__name__, 'socket')
+             self.assertEqual(module.__name__, 'this')
              invoked.append(1)
  
          self.assertEqual(len(invoked), 0)
  
-         import socket
+         import this
  
          self.assertEqual(len(invoked), 1)
  
  if __name__ == '__main__':
      unittest.main()
  
Adjust test to use different module as socket imported by coverage tools.
## Code Before:
from __future__ import print_function

import unittest

import wrapt

class TestPostImportHooks(unittest.TestCase):

    def test_simple(self):
        invoked = []

        @wrapt.when_imported('socket')
        def hook_socket(module):
            self.assertEqual(module.__name__, 'socket')
            invoked.append(1)

        self.assertEqual(len(invoked), 0)

        import socket

        self.assertEqual(len(invoked), 1)

if __name__ == '__main__':
    unittest.main()

## Instruction:
Adjust test to use different module as socket imported by coverage tools.
## Code After:
from __future__ import print_function

import unittest

import wrapt

class TestPostImportHooks(unittest.TestCase):

    def test_simple(self):
        invoked = []

        @wrapt.when_imported('this')
        def hook_this(module):
            self.assertEqual(module.__name__, 'this')
            invoked.append(1)

        self.assertEqual(len(invoked), 0)

        import this

        self.assertEqual(len(invoked), 1)

if __name__ == '__main__':
    unittest.main()
