Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#13049 closed enhancement (fixed)

Mercurial plugin tests

Reported by: Peter Suter Owned by:
Priority: normal Milestone: plugin - mercurial
Component: plugin/mercurial Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Added tests.

API Changes:
Internal Changes:

Description

Could tests be added for the Mercurial plugin? It would be nice if they can be run on the automated build systems and help find incompatibilities with new Mercurial releases.

Attachments (1)

hg_tests.patch (16.3 KB ) - added by Peter Suter 6 years ago.

Download all attachments as: .zip

Change History (20)

by Peter Suter, 6 years ago

Attachment: hg_tests.patch added

comment:1 by Peter Suter, 6 years ago

The attached patch just copies some of these Git tests. I omitted tests for bare repos and tests using "fast import data", and crudely modified the others until they passed for me, but I don't understand the the Trac version control system very well, so maybe this is misguided. What do you think?

comment:2 by Jun Omae, 6 years ago

#12160 was closed as duplicate.

comment:3 by Peter Suter, 6 years ago

Oops I forgot to check, thanks. Also I forgot a previous Git tests -> HG tests attempt for the HG command server approach.

comment:4 by Peter Suter, 6 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Pushed in [54/mercurial-plugin] for now.


It would be nice if they can be run on the automated build systems

Does anyone know if this is possible?

comment:5 by Jun Omae, 6 years ago

python setup.py test doesn't work.

  • setup.py

    diff -r e1d99e32bfa1 setup.py
    a b  
    5555          '': ['COPYING', 'README'],
    5656          'tracext.hg': ['locale/*.*', 'locale/*/LC_MESSAGES/*.*'],
    5757          },
     58      test_suite='tracext.hg.tests.test_suite',
    5859      entry_points={'trac.plugins': 'hg = tracext.hg.backend'},
    5960      **extra)

The unit tests run only with trunk.

  • tracext/hg/tests/backend.py

    diff -r e1d99e32bfa1 tracext/hg/tests/backend.py
    a b  
    1515import unittest
    1616from datetime import datetime, timedelta
    1717
    18 from trac.test import EnvironmentStub, MockRequest, mkdtemp, rmtree
     18from trac.test import EnvironmentStub, MockRequest, rmtree
    1919from trac.util import create_file
    2020from trac.util.datefmt import utc
    2121from trac.versioncontrol.api import Changeset, DbRepositoryProvider, \
     
    2525from trac.versioncontrol.web_ui.browser import BrowserModule
    2626from trac.versioncontrol.web_ui.log import LogModule
    2727
     28try:
     29    from trac.test import mkdtemp
     30except ImportError:
     31    import tempfile
     32    def mkdtemp():
     33        return os.path.realpath(tempfile.mkdtemp(prefix='trac-testdir-'))
     34
    2835from tracext.hg.backend import MercurialConnector, MercurialRepository
    2936
    3037import mercurial.commands

1 failure with Trac 1.0.15:

======================================================================
ERROR: test_get_system_info (tracext.hg.tests.backend.MercurialConnectorTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 345, in test_get_system_info
    self.assertIsNotNone(self._hg_version_from_system_info())
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 339, in _hg_version_from_system_info
    for name, version in self.env.system_info:
AttributeError: 'EnvironmentStub' object has no attribute 'system_info'

in reply to:  4 comment:6 by Jun Omae, 6 years ago

It would be nice if they can be run on the automated build systems

Does anyone know if this is possible?

I think we could use BitBucket piplelines after creating mirror of mercurial-plugin in https://bitbucket.org/edgewall/.

comment:7 by Ryan J Ollos, 6 years ago

@psuter: I can give you Maintainer access for publishing the new release to pypi:TracMercurial. Do you have a PyPI account?

in reply to:  5 ; comment:8 by Jun Omae, 6 years ago

1 failure with Trac 1.0.15:

======================================================================
ERROR: test_get_system_info (tracext.hg.tests.backend.MercurialConnectorTestCase)
----------------------------------------------------------------------
...
AttributeError: 'EnvironmentStub' object has no attribute 'system_info'

The system_info property is introduced in Trac 1.3.1dev.

Another issue, mercurial.commands.commit accepts iso8601 date string as date parameter since Mercurial 3.9.x. Prior to 3.9.0, it cannot.

Successfully installed Mercurial-3.8.4
running test
running egg_info
writing requirements to TracMercurial.egg-info/requires.txt
writing TracMercurial.egg-info/PKG-INFO
writing namespace_packages to TracMercurial.egg-info/namespace_packages.txt
writing top-level names to TracMercurial.egg-info/top_level.txt
writing dependency_links to TracMercurial.egg-info/dependency_links.txt
writing entry points to TracMercurial.egg-info/entry_points.txt
reading manifest file 'TracMercurial.egg-info/SOURCES.txt'
writing manifest file 'TracMercurial.egg-info/SOURCES.txt'
running build_ext
EEE.EEE.EEE.EEEE
======================================================================
ERROR: test_duplicate_repo (tracext.hg.tests.backend.SanityCheckingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 103, in test_duplicate_repo
    self._hg_init()
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 84, in _hg_init
    user='Joe', date=ts.isoformat())
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/commands.py", line 1682, in commit
    return _docommit(ui, repo, *pats, **opts)
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/commands.py", line 1771, in _docommit
    node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/cmdutil.py", line 2610, in commit
    opts['date'] = util.parsedate(date)
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/util.py", line 1724, in parsedate
    raise Abort(_('invalid date: %r') % date)
Abort: invalid date: '2001-01-29T16:39:56'

All versions of Mercurial accept rfc822 date string.

  • tracext/hg/tests/backend.py

    diff -r e1d99e32bfa1 tracext/hg/tests/backend.py
    a b  
    1515import unittest
    1616from datetime import datetime, timedelta
    1717
    18 from trac.test import EnvironmentStub, MockRequest, mkdtemp, rmtree
     18from trac.test import EnvironmentStub, MockRequest, rmtree
    1919from trac.util import create_file
    20 from trac.util.datefmt import utc
     20from trac.util.datefmt import http_date, utc
    2121from trac.versioncontrol.api import Changeset, DbRepositoryProvider, \
    2222                                    InvalidRepository, Node, \
    2323                                    NoSuchChangeset, NoSuchNode, \
     
    2525from trac.versioncontrol.web_ui.browser import BrowserModule
    2626from trac.versioncontrol.web_ui.log import LogModule
    2727
     28try:
     29    from trac.test import mkdtemp
     30except ImportError:
     31    import tempfile
     32    def mkdtemp():
     33        return os.path.realpath(tempfile.mkdtemp(prefix='trac-testdir-'))
     34
    2835from tracext.hg.backend import MercurialConnector, MercurialRepository
    2936
    3037import mercurial.commands
     
    7178        if data:
    7279            hgignore = os.path.join(self.repos_path, '.hgignore')
    7380            create_file(hgignore)
    74             ts = datetime(2001, 1, 29, 16, 39, 56)
     81            ts = datetime(2001, 1, 29, 16, 39, 56, 0, utc)
    7582            mercurial.commands.commit(self.hgui, self.hgrepo, hgignore,
    7683                                      message="test", addremove=True,
    77                                       user='Joe', date=ts.isoformat())
     84                                      user='Joe', date=http_date(ts))
    7885
    7986    def _create_commit(self, message, filename):
    8087        fullname = os.path.join(self.repos_path, filename)
     
    111118            create_file(filename, 'commit-%d.txt' % idx)
    112119            mercurial.commands.commit(self.hgui, self.hgrepo, filename,
    113120                                      message='%d' % idx, addremove=True,
    114                                       user='Joe', date=ts.isoformat())
     121                                      user='Joe', date=http_date(ts))
    115122        self._add_repository()
    116123        repos = self._repomgr.get_repository('hgrepos')
    117124        repos.repo.invalidate()
     
    327334
    328335class MercurialConnectorTestCase(BaseTestCase):
    329336
     337    if hasattr(EnvironmentStub, 'system_info'):
     338        def _get_system_info(self):
     339            return self.env.system_info
     340    else:
     341        def _get_system_info(self):
     342            return self.env.get_systeminfo()
     343
    330344    def _hg_version_from_system_info(self):
    331345        hg_version = None
    332         for name, version in self.env.system_info:
     346        for name, version in self._get_system_info():
    333347            if name == 'Mercurial':
    334348                hg_version = version
    335349        return hg_version

With Mercurial 3.7.x - 4.5.x, the following failures are occur. I'm not sure how to fix.

======================================================================
ERROR: test_duplicate_repo (tracext.hg.tests.backend.SanityCheckingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 103, in test_duplicate_repo
    self._hg_init()
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 84, in _hg_init
    user='Joe', date=ts.isoformat())
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/commands.py", line 1525, in commit
    return _docommit(ui, repo, *pats, **opts)
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/commands.py", line 1602, in _docommit
    node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/cmdutil.py", line 3129, in commit
    dsguard = dirstateguard.dirstateguard(repo, 'commit')
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/dirstateguard.py", line 36, in __init__
    repo.dirstate.savebackup(repo.currenttransaction(), self._backupname)
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/dirstate.py", line 1135, in savebackup
    checkambig=True))
  File "/dev/shm/hgtest/local/lib/python2.7/site-packages/mercurial/dirstate.py", line 650, in _writedirstate
    now = util.fstat(st).st_mtime & _rangemask
TypeError: unsupported operand type(s) for &: 'float' and 'int'

comment:9 by Peter Suter, 6 years ago

Thanks, the proposed changes sound good to me. Looks like running the tests automatically for old and new versions of Mercurial and Trac would be helpful. Maybe Bitbucket Scheduled Pipelines can be used?

Do you have a PyPI account?

I created PyPI account psuter.

in reply to:  8 ; comment:10 by Peter Suter, 6 years ago

With Mercurial 3.7.x - 4.5.x, the following failures are occur. I'm not sure how to fix.

    ...
    now = util.fstat(st).st_mtime & _rangemask
TypeError: unsupported operand type(s) for &: 'float' and 'int'

Is this related to your findings in comment:10:ticket:10411?

in reply to:  10 ; comment:11 by Jun Omae, 6 years ago

Replying to Peter Suter:

With Mercurial 3.7.x - 4.5.x, the following failures are occur. I'm not sure how to fix.

    ...
    now = util.fstat(st).st_mtime & _rangemask
TypeError: unsupported operand type(s) for &: 'float' and 'int'

Is this related to your findings in comment:10:ticket:10411?

Yeah, the errors go away after os.stat_float_times(False) is manually added to tracext/hg/tests/backend.py. However, I think the behavior is weird. The os.stat_float_times(False) is automaticaly invoked by import mercurial.util.

Anyway, 1 failure occurs with Mercurial 3.7.x - 4.5.x:

======================================================================
ERROR: test_annotate (tracext.hg.tests.backend.RegressionsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 381, in test_annotate
    self.assertEqual([1], node.get_annotations())
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 1252, in get_annotations
    annotations.append(fc.rev() or '0')
AttributeError: 'annotateline' object has no attribute 'rev'
  • tracext/hg/backend.py

    diff -r e1d99e32bfa1 tracext/hg/backend.py
    a b  
    12461246                    fc = annotateline[0]
    12471247                    if isinstance(fc, tuple):
    12481248                        fc = fc[0]
     1249                    elif not isinstance(fc, filectx):
     1250                        fc = fc.fctx
    12491251                else:
    12501252                    fc = annotateline.fctx
    12511253                annotations.append(fc.rev() or '0')

comment:12 by Peter Suter, 6 years ago

All versions of Mercurial accept rfc822 date string.

Using http_date in Mercurial 4.6.1 I get:

Traceback (most recent call last):
  File "C:\src\mercurial-plugin\tracext\hg\tests\backend.py", line 103, in test_duplicate_repo
    self._hg_init()
  File "C:\src\mercurial-plugin\tracext\hg\tests\backend.py", line 84, in _hg_init
    date=http_date(ts))
  File "C:\venv_py27\lib\site-packages\mercurial\commands.py", line 1543, in commit
    return _docommit(ui, repo, *pats, **opts)
  File "C:\venv_py27\lib\site-packages\mercurial\commands.py", line 1620, in _docommit
    node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
  File "C:\venv_py27\lib\site-packages\mercurial\cmdutil.py", line 2357, in commit
    opts['date'] = dateutil.parsedate(date)
  File "C:\venv_py27\lib\site-packages\mercurial\utils\dateutil.py", line 247, in parsedate
    _('invalid date: %r') % pycompat.bytestr(date))
ParseError: invalid date: 'Mon, 29 Jan 2001 16:39:56 GMT'

in reply to:  9 comment:13 by Ryan J Ollos, 6 years ago

Replying to Peter Suter:

Do you have a PyPI account?

I created PyPI account psuter.

I've added you a project owner. To create and upload a release for PyPI:

$ python setup.py sdist bdist_wheel
$ twine upload dist/*.tar.gz dist/*.whl
Last edited 6 years ago by Ryan J Ollos (previous) (diff)

in reply to:  12 comment:14 by Jun Omae, 6 years ago

All versions of Mercurial accept rfc822 date string.

Using http_date in Mercurial 4.6.1 I get:

...
ParseError: invalid date: 'Mon, 29 Jan 2001 16:39:56 GMT'

Oh, thanks. Fixed in [058df3c9e351/mercurial-plugin].

in reply to:  11 comment:15 by Jun Omae, 6 years ago

Replying to Jun Omae:

Replying to Peter Suter:

With Mercurial 3.7.x - 4.5.x, the following failures are occur. I'm not sure how to fix.

    ...
    now = util.fstat(st).st_mtime & _rangemask
TypeError: unsupported operand type(s) for &: 'float' and 'int'

Is this related to your findings in comment:10:ticket:10411?

Yeah, the errors go away after os.stat_float_times(False) is manually added to tracext/hg/tests/backend.py. However, I think the behavior is weird. The os.stat_float_times(False) is automaticaly invoked by import mercurial.util.

This behavior is because tracext/hg/backend.py restores os.stat_float_times()'s value at mercurial-plugin/tracext/hg/backend.py@e5f80d909b3f#L133.

Also, I found work around to use os.stat_float_times(False) while writing repository and working copy. Proposed changes in https://bitbucket.org/jun66j5/mercurial-plugin/commits/a236958adc560f5f0536cd5a6770f9f19d9a646a.

Anyway, 1 failure occurs with Mercurial 3.7.x - 4.5.x:

======================================================================
ERROR: test_annotate (tracext.hg.tests.backend.RegressionsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/tests/backend.py", line 381, in test_annotate
    self.assertEqual([1], node.get_annotations())
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 1252, in get_annotations
    annotations.append(fc.rev() or '0')
AttributeError: 'annotateline' object has no attribute 'rev'
  • tracext/hg/backend.py

    diff -r e1d99e32bfa1 tracext/hg/backend.py
    a b  
    12461246                    fc = annotateline[0]
    12471247                    if isinstance(fc, tuple):
    12481248                        fc = fc[0]
     1249                    elif not isinstance(fc, filectx):
     1250                        fc = fc.fctx
    12491251                else:
    12501252                    fc = annotateline.fctx
    12511253                annotations.append(fc.rev() or '0')

Proposed changes in https://bitbucket.org/jun66j5/mercurial-plugin/commits/923f81dadc2f5685dd683c810b5149b6edfac983. The fix and revised unit tests are included.

comment:16 by Peter Suter, 6 years ago

The proposed changes look very good to me.

in reply to:  16 comment:17 by Jun Omae, 6 years ago

The proposed changes look very good to me.

Thanks. Pushed the two commits in mercurial-plugin@a236958adc56:923f81dadc2f.

in reply to:  9 ; comment:18 by Ryan J Ollos, 6 years ago

Replying to Peter Suter:

Thanks, the proposed changes sound good to me. Looks like running the tests automatically for old and new versions of Mercurial and Trac would be helpful. Maybe Bitbucket Scheduled Pipelines can be used?

You might be able to do the same on Travis CI and AppVeyor. We have quite a bit of effort invested in running tests and deploying (#12833) on those platforms.

in reply to:  18 comment:19 by Jun Omae, 6 years ago

Replying to Ryan J Ollos:

Replying to Peter Suter:

Thanks, the proposed changes sound good to me. Looks like running the tests automatically for old and new versions of Mercurial and Trac would be helpful. Maybe Bitbucket Scheduled Pipelines can be used?

Yes. The scheduled pipelines is helpful to run unit tests with latest marcurial.

Minimum configuration: https://bitbucket.org/jun66j5/mercurial-plugin/commits/096b7acf79659b0aca190ffcad234f6b136081be

However, BitBucket pipelines seems to be missing build matrix feature. It is not easy to test with all combination of the versions (e.g. Mercurial (3.6, 3.7, 4.5, 4.6) x Trac (1.0, 1.2, trunk)).

You might be able to do the same on Travis CI and AppVeyor. We have quite a bit of effort invested in running tests and deploying (#12833) on those platforms.

The mercurial-plugin is in mercurial repository. I think it needs to convert mercurial repository to git to use Travis CI and AppVeyor.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from (none) to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.