Mercurial > python-hglib
changeset 7:eac8be119d81
tests: rearrange tests and use nosetests
- provide package setup/teardown methods that fixes the environment
- introduce a basetest that initializes a repository in a temp dir
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sat, 23 Jul 2011 22:55:39 +0300 |
parents | 96f8c5095e2e |
children | 3ac38d500d68 |
files | .hgignore Makefile tests/__init__.py tests/common.py tests/test-branch.py tests/test-encoding.py tests/test-hglib.py tests/test-import.py tests/test-log.py tests/test-outgoing-incoming.py tests/test-paths.py |
diffstat | 11 files changed, 140 insertions(+), 114 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sat Jul 23 22:55:39 2011 +0300 +++ b/.hgignore Sat Jul 23 22:55:39 2011 +0300 @@ -5,3 +5,4 @@ *.rej *~ *.swp +*.noseids
--- a/Makefile Sat Jul 23 22:55:39 2011 +0300 +++ b/Makefile Sat Jul 23 22:55:39 2011 +0300 @@ -8,4 +8,4 @@ .PHONY: tests tests: - cd tests && $(PYTHON) $(HGREPO)/tests/run-tests.py -l $(TESTFLAGS) + nosetests --with-doctest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/__init__.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,21 @@ +import os, tempfile, sys, shutil + +def setUp(): + os.environ['LANG'] = os.environ['LC_ALL'] = os.environ['LANGUAGE'] = 'C' + os.environ['TZ'] = 'GMT' + os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>" + os.environ['CDPATH'] = '' + os.environ['COLUMNS'] = '80' + os.environ['GREP_OPTIONS'] = '' + os.environ['http_proxy'] = '' + + os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' + os.environ["HGMERGE"] = "internal:merge" + os.environ["HGUSER"] = "test" + os.environ["HGENCODING"] = "ascii" + os.environ["HGENCODINGMODE"] = "strict" + tmpdir = tempfile.mkdtemp('', 'python-hglib.') + os.environ["HGTMP"] = os.path.realpath(tmpdir) + +def tearDown(self): + shutil.rmtree(os.environ["HGTMP"])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/common.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,24 @@ +import os, sys, tempfile, shutil +import unittest + +import hglib + +class basetest(unittest.TestCase): + def setUp(self): + self._testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \ + os.path.join(os.environ["HGTMP"], self.__class__.__name__) + + os.mkdir(self._testtmp) + os.chdir(self._testtmp) + # until we can run norepo commands in the cmdserver + os.system('hg init') + self.client = hglib.open() + + def tearDown(self): + shutil.rmtree(self._testtmp) + + def append(self, path, *args): + f = open(path, 'a') + for a in args: + f.write(str(a)) + f.close()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-branch.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,11 @@ +import common +import hglib + +class test_branch(common.basetest): + def test_basic(self): + self.assertEquals(self.client.branch(), 'default') + self.append('a', 'a') + rev = self.client.commit('first', addremove=True) + branches = self.client.branches() + + self.assertEquals(rev, branches[rev.branch])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-encoding.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,7 @@ +import common +import hglib + +class test_encoding(common.basetest): + def test_basic(self): + self.client = hglib.open(encoding='utf-8') + self.assertEquals(self.client.encoding, 'utf-8')
--- a/tests/test-hglib.py Sat Jul 23 22:55:39 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -#!/usr/bin/env python - -import unittest - -import sys, os, subprocess, cStringIO, shutil, tempfile - -sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../') -import hglib - -class test_hglib(unittest.TestCase): - def setUp(self): - self._tmpdir = tempfile.mkdtemp() - os.chdir(self._tmpdir) - # until we can run norepo commands in the cmdserver - os.system('hg init') - self.client = hglib.open() - - def tearDown(self): - shutil.rmtree(self._tmpdir) - - def append(self, path, *args): - f = open(path, 'a') - for a in args: - f.write(str(a)) - f.close() - - def test_log(self): - self.append('a', 'a') - rev0 = self.client.commit('first', addremove=True) - self.append('a', 'a') - rev1 = self.client.commit('second') - - revs = self.client.log() - revs.reverse() - - self.assertTrue(len(revs) == 2) - self.assertEquals(revs[1], rev1) - - self.assertEquals(revs[0], self.client.log('0')[0]) - - def test_outgoing_incoming(self): - self.append('a', 'a') - self.client.commit('first', addremove=True) - self.append('a', 'a') - self.client.commit('second') - - self.client.clone(dest='bar') - bar = hglib.open('bar') - - self.assertEquals(self.client.log(), bar.log()) - self.assertEquals(self.client.outgoing(path='bar'), bar.incoming()) - - self.append('a', 'a') - rev = self.client.commit('third') - out = self.client.outgoing(path='bar') - - self.assertEquals(len(out), 1) - self.assertEquals(out[0], rev) - - self.assertEquals(out, bar.incoming()) - - def test_branch(self): - self.assertEquals(self.client.branch(), 'default') - self.append('a', 'a') - rev = self.client.commit('first', addremove=True) - branches = self.client.branches() - - self.assertEquals(rev, branches[rev.branch]) - - def test_encoding(self): - self.client = hglib.open(encoding='utf-8') - self.assertEquals(self.client.encoding, 'utf-8') - - def test_paths(self): - open('.hg/hgrc', 'a').write('[paths]\nfoo = bar\n') - - # hgrc isn't watched for changes yet, have to reconnect - self.client = hglib.open() - paths = self.client.paths() - self.assertEquals(len(paths), 1) - self.assertEquals(paths['foo'], os.path.abspath('bar')) - self.assertEquals(self.client.paths('foo'), os.path.abspath('bar')) - - def test_import(self): - patch = """ -# HG changeset patch -# User test -# Date 0 0 -# Node ID c103a3dec114d882c98382d684d8af798d09d857 -# Parent 0000000000000000000000000000000000000000 -1 - -diff -r 000000000000 -r c103a3dec114 a ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/a Thu Jan 01 00:00:00 1970 +0000 -@@ -0,0 +1,1 @@ -+1 -""" - self.client.import_(cStringIO.StringIO(patch)) - self.assertEquals(self.client.cat(['a']), '1\n') - -if __name__ == '__main__': - stream = cStringIO.StringIO() - runner = unittest.TextTestRunner(stream=stream, verbosity=0) - - # XXX fix this - module = __import__('__main__') - loader = unittest.TestLoader() - ret = not runner.run(loader.loadTestsFromModule(module)).wasSuccessful() - if ret: - print stream.getvalue() - - sys.exit(ret)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-import.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,21 @@ +import common, cStringIO +import hglib + +class test_import(common.basetest): + def test_basic(self): + patch = """ +# HG changeset patch +# User test +# Date 0 0 +# Node ID c103a3dec114d882c98382d684d8af798d09d857 +# Parent 0000000000000000000000000000000000000000 +1 + +diff -r 000000000000 -r c103a3dec114 a +--- /dev/null Thu Jan 01 00:00:00 1970 +0000 ++++ b/a Thu Jan 01 00:00:00 1970 +0000 +@@ -0,0 +1,1 @@ ++1 +""" + self.client.import_(cStringIO.StringIO(patch)) + self.assertEquals(self.client.cat(['a']), '1\n')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-log.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,17 @@ +import common +import hglib + +class test_log(common.basetest): + def test_basic(self): + self.append('a', 'a') + rev0 = self.client.commit('first', addremove=True) + self.append('a', 'a') + rev1 = self.client.commit('second') + + revs = self.client.log() + revs.reverse() + + self.assertTrue(len(revs) == 2) + self.assertEquals(revs[1], rev1) + + self.assertEquals(revs[0], self.client.log('0')[0])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-outgoing-incoming.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,24 @@ +import common +import hglib + +class test_outgoing_incoming(common.basetest): + def test_basic(self): + self.append('a', 'a') + self.client.commit('first', addremove=True) + self.append('a', 'a') + self.client.commit('second') + + self.client.clone(dest='bar') + bar = hglib.open('bar') + + self.assertEquals(self.client.log(), bar.log()) + self.assertEquals(self.client.outgoing(path='bar'), bar.incoming()) + + self.append('a', 'a') + rev = self.client.commit('third') + out = self.client.outgoing(path='bar') + + self.assertEquals(len(out), 1) + self.assertEquals(out[0], rev) + + self.assertEquals(out, bar.incoming())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-paths.py Sat Jul 23 22:55:39 2011 +0300 @@ -0,0 +1,13 @@ +import common, os +import hglib + +class test_paths(common.basetest): + def test_basic(self): + open('.hg/hgrc', 'a').write('[paths]\nfoo = bar\n') + + # hgrc isn't watched for changes yet, have to reopen + self.client = hglib.open() + paths = self.client.paths() + self.assertEquals(len(paths), 1) + self.assertEquals(paths['foo'], os.path.abspath('bar')) + self.assertEquals(self.client.paths('foo'), os.path.abspath('bar'))