[Python-checkins] r52262 - sandbox/trunk/import_in_py/test_importer.py
brett.cannon
python-checkins at python.org
Tue Oct 10 02:01:39 CEST 2006
Author: brett.cannon
Date: Tue Oct 10 02:01:38 2006
New Revision: 52262
Modified:
sandbox/trunk/import_in_py/test_importer.py
Log:
Initial set of tests for Python source handler.
Modified: sandbox/trunk/import_in_py/test_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importer.py (original)
+++ sandbox/trunk/import_in_py/test_importer.py Tue Oct 10 02:01:38 2006
@@ -1,8 +1,12 @@
+from __future__ import with_statement
import unittest
from test import test_support
import importer
import sys
import StringIO
+import os
+import tempfile
+import new
class BuiltinFrozen_Tester(unittest.TestCase):
@@ -105,10 +109,43 @@
sys.stdout = self._orig_stdout
+class SourceHandlerTests(unittest.TestCase):
+
+ """Test the Python source code handler."""
+
+ def setUp(self):
+ """Generate the path to a temporary file to test with."""
+ self.test_module = 'source_tester'
+ self.test_dir = tempfile.gettempdir()
+ self.file_path = os.path.join(self.test_dir, self.test_module+'.py')
+ self.handler = importer.PySourceHandler()
+
+ def tearDown(self):
+ """If the temporary path was used, make sure to clean up."""
+ if os.path.exists(self.file_path):
+ os.remove(self.file_path)
+
+ def test_handle(self):
+ # Should claim it handles 'py' data.
+ self.failUnlessEqual(self.handler.handles, 'py')
+
+ def test_handle_file_module(self):
+ # Should be handle a module that is directly pointed at.
+ with open(self.file_path, 'w') as py_file:
+ py_file.write("test_attr = None")
+ new_module = new.module(self.test_module)
+ self.handler.handle_file(new_module, self.test_module,
+ None, self.file_path)
+ self.failUnlessEqual(self.test_module, new_module.__name__)
+ self.failUnlessEqual(self.file_path, new_module.__file__)
+ self.failUnless(hasattr(new_module, 'test_attr'))
+
+
def test_main():
test_support.run_unittest(
BuiltinImporterTests,
FrozenImporterTests,
+ SourceHandlerTests,
)
More information about the Python-checkins
mailing list