[Pkg-bazaar-commits] ./bzr/unstable r732: - move more tests into bzr selftest
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:20:51 UTC 2009
------------------------------------------------------------
revno: 732
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Wed 2005-06-22 16:18:20 +1000
message:
- move more tests into bzr selftest
modified:
bzrlib/selftest/__init__.py
bzrlib/selftest/blackbox.py
testbzr
-------------- next part --------------
=== modified file 'bzrlib/selftest/__init__.py'
--- a/bzrlib/selftest/__init__.py 2005-06-21 08:35:05 +0000
+++ b/bzrlib/selftest/__init__.py 2005-06-22 06:18:20 +0000
@@ -76,12 +76,43 @@
% (cmd, actual_retcode, retcode))
+ def backtick(self, cmd, retcode=0):
+ cmd = self.formcmd(cmd)
+ child = Popen(cmd, stdout=PIPE, stderr=self.TEST_LOG)
+ outd, errd = child.communicate()
+ self.log(outd)
+ actual_retcode = child.wait()
+
+ outd = outd.replace('\r', '')
+
+ if retcode != actual_retcode:
+ raise CommandFailed("test failed: %r returned %d, expected %d"
+ % (cmd, actual_retcode, retcode))
+
+ return outd
+
+
+
def log(self, msg):
"""Log a message to a progress file"""
print >>self.TEST_LOG, msg
+class InTempDir(TestBase):
+ """Base class for tests run in a temporary branch."""
+ def setUp(self):
+ import os
+ self.branch_dir = os.path.join(self.TEST_DIR, self.__class__.__name__)
+ os.mkdir(self.branch_dir)
+ os.chdir(self.branch_dir)
+
+ def tearDown(self):
+ import os
+ os.chdir(self.TEST_DIR)
+
+
+
class _MyResult(TestResult):
=== modified file 'bzrlib/selftest/blackbox.py'
--- a/bzrlib/selftest/blackbox.py 2005-06-21 08:35:05 +0000
+++ b/bzrlib/selftest/blackbox.py 2005-06-22 06:18:20 +0000
@@ -28,7 +28,7 @@
# this code was previously in testbzr
from unittest import TestCase
-from bzrlib.selftest import TestBase
+from bzrlib.selftest import TestBase, InTempDir
class TestVersion(TestBase):
def runTest(self):
@@ -49,25 +49,21 @@
self.runcmd('bzr commit -h')
-class InTempBranch(TestBase):
- """Base class for tests run in a temporary branch."""
- def setUp(self):
- import os
- self.branch_dir = os.path.join(self.TEST_DIR, self.__class__.__name__)
- os.mkdir(self.branch_dir)
- os.chdir(self.branch_dir)
-
- def tearDown(self):
- import os
- os.chdir(self.TEST_DIR)
-
-
-class InitBranch(InTempBranch):
+class InitBranch(InTempDir):
def runTest(self):
import os
print "%s running in %s" % (self, os.getcwdu())
self.runcmd(['bzr', 'init'])
-
+
+
+
+class UserIdentity(InTempDir):
+ def runTest(self):
+ # this should always identify something, if only "john at localhost"
+ self.runcmd("bzr whoami")
+ self.runcmd("bzr whoami --email")
+ self.assertEquals(self.backtick("bzr whoami --email").count('@'),
+ 1)
@@ -81,5 +77,6 @@
s = TestSuite()
s.addTests([TestVersion(),
InitBranch(),
- HelpCommands()])
+ HelpCommands(),
+ UserIdentity()])
return s
=== modified file 'testbzr'
--- a/testbzr 2005-06-22 06:04:43 +0000
+++ b/testbzr 2005-06-22 06:18:20 +0000
@@ -149,56 +149,6 @@
logfile = open(LOGFILENAME, 'wt', buffering=1)
-def test_plugins():
- """Run a test involving creating a plugin to load,
- and making sure it is seen properly.
- """
- orig_help = backtick('bzr help commands') # No plugins yet
- mkdir('plugin_test')
- f = open(os.path.join('plugin_test', 'myplug.py'), 'wb')
- f.write("""import bzrlib, bzrlib.commands
-class cmd_myplug(bzrlib.commands.Command):
- '''Just a simple test plugin.'''
- aliases = ['mplg']
- def run(self):
- print 'Hello from my plugin'
-""")
- f.close()
-
- os.environ['BZRPLUGINPATH'] = os.path.abspath('plugin_test')
- help = backtick('bzr help commands')
- assert help.find('myplug') != -1
- assert help.find('Just a simple test plugin.') != -1
-
-
- assert backtick('bzr myplug') == 'Hello from my plugin\n'
- assert backtick('bzr mplg') == 'Hello from my plugin\n'
-
- f = open(os.path.join('plugin_test', 'override.py'), 'wb')
- f.write("""import bzrlib, bzrlib.commands
-class cmd_commit(bzrlib.commands.cmd_commit):
- '''Commit changes into a new revision.'''
- def run(self, *args, **kwargs):
- print "I'm sorry dave, you can't do that"
-
-class cmd_help(bzrlib.commands.cmd_help):
- '''Show help on a command or other topic.'''
- def run(self, *args, **kwargs):
- print "You have been overridden"
- bzrlib.commands.cmd_help.run(self, *args, **kwargs)
-
-""")
- f.close()
-
- newhelp = backtick('bzr help commands')
- assert newhelp.startswith('You have been overridden\n')
- # We added a line, but the rest should work
- assert newhelp[25:] == help
-
- assert backtick('bzr commit -m test') == "I'm sorry dave, you can't do that\n"
-
- shutil.rmtree('plugin_test')
-
try:
from getopt import getopt
opts, args = getopt(sys.argv[1:], 'p:')
@@ -240,12 +190,6 @@
progress("internal tests")
runcmd("bzr selftest")
- progress("user identity")
- # this should always identify something, if only "john at localhost"
- runcmd("bzr whoami")
- runcmd("bzr whoami --email")
- assert backtick("bzr whoami --email").count('@') == 1
-
progress("invalid commands")
runcmd("bzr pants", retcode=1)
runcmd("bzr --pants off", retcode=1)
More information about the Pkg-bazaar-commits
mailing list