def test_state_after_failure(self):
    attributes = ('__file__', '__path__', '__package__')
    value = '<test>'
    name = '_temp'
    with util.create_modules(name) as mapping:
        orig_module = types.ModuleType(name)
        for attr in attributes:
            setattr(orig_module, attr, value)
        with open(mapping[name], 'w') as file:
            file.write('+++ bad syntax +++')
        loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
        with self.assertRaises(SyntaxError):
            loader.exec_module(orig_module)
        for attr in attributes:
            self.assertEqual(getattr(orig_module, attr), value)
        with self.assertRaises(SyntaxError):
            with warnings.catch_warnings():
                warnings.simplefilter('ignore', DeprecationWarning)
                loader.load_module(name)
        for attr in attributes:
            self.assertEqual(getattr(orig_module, attr), value)
def test_state_after_failure(self):
    attributes = ('__file__', '__path__', '__package__')
    value = '<test>'
    name = '_temp'
    with util.create_modules(name) as mapping:
        orig_module = types.ModuleType(name)
        for attr in attributes:
            setattr(orig_module, attr, value)
        with open(mapping[name], 'w') as file:
            file.write('+++ bad syntax +++')
        loader = self.machinery.SourceFileLoader('_temp', mapping['_temp'])
        with self.assertRaises(SyntaxError):
            loader.exec_module(orig_module)
        for attr in attributes:
            self.assertEqual(getattr(orig_module, attr), value)
        with self.assertRaises(SyntaxError):
            with warnings.catch_warnings():
                warnings.simplefilter('ignore', DeprecationWarning)
                loader.load_module(name)
        for attr in attributes:
            self.assertEqual(getattr(orig_module, attr), value)