Rev 3: Test importing a trivial package. in file:///home/robertc/source/baz/plugins/piss/trunk/
Robert Collins
robertc at robertcollins.net
Tue May 1 12:32:31 BST 2007
At file:///home/robertc/source/baz/plugins/piss/trunk/
------------------------------------------------------------
revno: 3
revision-id: robertc at robertcollins.net-20070501113231-tdboinla71qnr459
parent: robertc at robertcollins.net-20070501102058-1pxfxfw3lll24kwp
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Tue 2007-05-01 21:32:31 +1000
message:
Test importing a trivial package.
modified:
benchmarks/bench_import.py bench_import.py-20070501062416-23ztx65da4ul4oxv-7
creator.py creator.py-20070501064357-lwoaimjvnf8252jd-1
tests/test_creator.py test_creator.py-20070501064357-lwoaimjvnf8252jd-4
=== modified file 'benchmarks/bench_import.py'
--- a/benchmarks/bench_import.py 2007-05-01 10:20:58 +0000
+++ b/benchmarks/bench_import.py 2007-05-01 11:32:31 +0000
@@ -27,15 +27,30 @@
class BenchImport(TestCaseWithTransport):
+ def setUp(self):
+ TestCaseWithTransport.setUp(self)
+ self.creator = _mod_creator.Creator()
+
def test_import_tiny_module(self):
+ self.add_cwd_to_path()
+ # import once to generate a .pyc - the common case.
+ self.creator.build_module('tiny_piss')
+ self.import_and_forget('tiny_piss')
+ self.time(self.import_and_forget, 'tiny_piss')
+
+ def test_import_tiny_package(self):
+ self.add_cwd_to_path()
+ # import once to generate a .pyc - the common case.
+ self.creator.build_package('tiny_piss')
+ self.import_and_forget('tiny_piss')
+ self.time(self.import_and_forget, 'tiny_piss')
+
+ def add_cwd_to_path(self):
sys.path.append(os.getcwd())
self.addCleanup(lambda: sys.path.pop(-1))
- # import once to generate a .pyc - the common case.
- creator = _mod_creator.Creator()
- creator.build_module('tiny_piss')
- import tiny_piss
- sys.modules.pop('tiny_piss')
- def import_tiny():
- import tiny_piss
- self.addCleanup(lambda: sys.modules.pop('tiny_piss'))
- self.time(import_tiny)
+
+ def import_and_forget(self, module_name):
+ try:
+ exec 'import %s' % module_name
+ finally:
+ sys.modules.pop(module_name)
=== modified file 'creator.py'
--- a/creator.py 2007-05-01 10:20:58 +0000
+++ b/creator.py 2007-05-01 11:32:31 +0000
@@ -36,3 +36,7 @@
os.unlink(path)
raise
+ def build_package(self, name):
+ """Create a package called name in the cwd."""
+ os.mkdir(name)
+ self.build_module(name + '/__init__')
=== modified file 'tests/test_creator.py'
--- a/tests/test_creator.py 2007-05-01 10:20:58 +0000
+++ b/tests/test_creator.py 2007-05-01 11:32:31 +0000
@@ -33,3 +33,9 @@
creator = _mod_creator.Creator()
creator.build_module('foo')
self.assertEqual('', self.get_transport().get_bytes('foo.py'))
+
+ def test_build_package(self):
+ # building a package called 'foo' should make a foo/__init__.py
+ creator = _mod_creator.Creator()
+ creator.build_package('foo')
+ self.assertEqual('', self.get_transport().get_bytes('foo/__init__.py'))
More information about the bazaar-commits
mailing list