Rev 2: Add benchmark for importing an empty module in the root of the path. in file:///home/robertc/source/baz/plugins/piss/trunk/
Robert Collins
robertc at robertcollins.net
Tue May 1 11:20:59 BST 2007
At file:///home/robertc/source/baz/plugins/piss/trunk/
------------------------------------------------------------
revno: 2
revision-id: robertc at robertcollins.net-20070501102058-1pxfxfw3lll24kwp
parent: robertc at robertcollins.net-20070501090031-jebq3hno650idoec
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Tue 2007-05-01 20:20:58 +1000
message:
Add benchmark for importing an empty module in the root of the path.
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 09:00:31 +0000
+++ b/benchmarks/bench_import.py 2007-05-01 10:20:58 +0000
@@ -18,11 +18,24 @@
"""Benchmarks of various python import times."""
-
-from bzrlib.tests import TestCaseInTempDir
-
-
-class BenchImport(TestCaseInTempDir):
-
- def test_stub(self):
- pass
+import os
+import sys
+
+from bzrlib.plugins.piss import creator as _mod_creator
+from bzrlib.tests import TestCaseWithTransport
+
+
+class BenchImport(TestCaseWithTransport):
+
+ def test_import_tiny_module(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)
=== modified file 'creator.py'
--- a/creator.py 2007-05-01 09:00:31 +0000
+++ b/creator.py 2007-05-01 10:20:58 +0000
@@ -18,6 +18,21 @@
"""A tool to create arbitrary python modules/packages."""
+import os
class Creator(object):
"""A creator of python modules/packages."""
+
+ def build_module(self, name):
+ """Build a module in cwd called name."""
+ path = name + '.py'
+ output = file(path, 'wt+')
+ try:
+ try:
+ output.write('')
+ finally:
+ output.close()
+ except:
+ os.unlink(path)
+ raise
+
=== modified file 'tests/test_creator.py'
--- a/tests/test_creator.py 2007-05-01 09:00:31 +0000
+++ b/tests/test_creator.py 2007-05-01 10:20:58 +0000
@@ -19,11 +19,17 @@
"""Tests for the python module creator."""
-from bzrlib.plugins.piss import creator
-from bzrlib.tests import TestCaseInTempDir
-
-
-class TestCreator(TestCaseInTempDir):
+from bzrlib.plugins.piss import creator as _mod_creator
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestCreator(TestCaseWithTransport):
def test_construct(self):
- creator.Creator()
+ _mod_creator.Creator()
+
+ def test_build_module(self):
+ # building a module called 'foo' should make a foo.py
+ creator = _mod_creator.Creator()
+ creator.build_module('foo')
+ self.assertEqual('', self.get_transport().get_bytes('foo.py'))
More information about the bazaar-commits
mailing list