[PATCH hglib] tests: rearrange tests and use nosetests

Idan Kamara idankk86 at gmail.com
Mon Aug 8 17:57:45 CDT 2011


On Tue, Aug 9, 2011 at 1:43 AM, Matt Mackall <mpm at selenic.com> wrote:
>
> On Tue, 2011-08-09 at 00:42 +0300, Idan Kamara wrote:
> > # HG changeset patch
> > # User Idan Kamara <idankk86 at gmail.com>
> > # Date 1311450939 -10800
> > # Node ID 1e08687a2034a8c3470bcdbe669febad8773ea9e
> > # Parent  fb0b2708717964d486c96eb122ab60bb81a882a6
> > tests: rearrange tests and use nosetests
>
> What is a nosetest? It sounds like a new dependency.

It's a new dependency to run the test suite.

>From their site: "A unittest-based testing framework for python that makes
writing and running tests easier".

And I found that to be true, because after installing it and just running
"nosetests" at the root dir,
I had all tests running with a problem. OTOH after reading most of Python's
unittest docs, I couldn't get
it to do what I want after a good hour or two.

FWIW I haven't actually used any of nose Python features, just the discovery
and doctest integration bit.

>
> Why is this patch apparently doing two different things?

I guess because it was easier to do it all at once.

>
> > - provide package setup/teardown methods that fixes the environment
> > - introduce a basetest that initializes a repository in a temp dir
> >
> > diff -r fb0b27087179 -r 1e08687a2034 .hgignore
> > --- a/.hgignore       Tue Aug 09 00:41:31 2011 +0300
> > +++ b/.hgignore       Sat Jul 23 22:55:39 2011 +0300
> > @@ -5,3 +5,4 @@
> >  *.rej
> >  *~
> >  *.swp
> > +*.noseids
> > diff -r fb0b27087179 -r 1e08687a2034 Makefile
> > --- a/Makefile        Tue Aug 09 00:41:31 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
> > diff -r fb0b27087179 -r 1e08687a2034 tests/__init__.py
> > --- /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 at 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"])
> > diff -r fb0b27087179 -r 1e08687a2034 tests/common.py
> > --- /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()
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-branch.py
> > --- /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])
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-encoding.py
> > --- /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')
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-hglib.py
> > --- a/tests/test-hglib.py     Tue Aug 09 00:41:31 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)
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-import.py
> > --- /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')
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-log.py
> > --- /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])
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-outgoing-incoming.py
> > --- /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())
> > diff -r fb0b27087179 -r 1e08687a2034 tests/test-paths.py
> > --- /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'))
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel at selenic.com
> > http://selenic.com/mailman/listinfo/mercurial-devel
>
>
> --
> Mathematics is the supreme nostalgia of our time.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110809/f07d20f8/attachment.html>


More information about the Mercurial-devel mailing list