#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)
Change History (20)
by , 7 years ago
Attachment: | hg_tests.patch added |
---|
comment:1 by , 7 years ago
comment:3 by , 7 years ago
Oops I forgot to check, thanks. Also I forgot a previous Git tests -> HG tests attempt for the HG command server approach.
follow-up: 6 comment:4 by , 7 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
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?
follow-up: 8 comment:5 by , 7 years ago
python setup.py test
doesn't work.
-
setup.py
diff -r e1d99e32bfa1 setup.py
a b 55 55 '': ['COPYING', 'README'], 56 56 'tracext.hg': ['locale/*.*', 'locale/*/LC_MESSAGES/*.*'], 57 57 }, 58 test_suite='tracext.hg.tests.test_suite', 58 59 entry_points={'trac.plugins': 'hg = tracext.hg.backend'}, 59 60 **extra)
The unit tests run only with trunk.
-
tracext/hg/tests/backend.py
diff -r e1d99e32bfa1 tracext/hg/tests/backend.py
a b 15 15 import unittest 16 16 from datetime import datetime, timedelta 17 17 18 from trac.test import EnvironmentStub, MockRequest, mkdtemp,rmtree18 from trac.test import EnvironmentStub, MockRequest, rmtree 19 19 from trac.util import create_file 20 20 from trac.util.datefmt import utc 21 21 from trac.versioncontrol.api import Changeset, DbRepositoryProvider, \ … … 25 25 from trac.versioncontrol.web_ui.browser import BrowserModule 26 26 from trac.versioncontrol.web_ui.log import LogModule 27 27 28 try: 29 from trac.test import mkdtemp 30 except ImportError: 31 import tempfile 32 def mkdtemp(): 33 return os.path.realpath(tempfile.mkdtemp(prefix='trac-testdir-')) 34 28 35 from tracext.hg.backend import MercurialConnector, MercurialRepository 29 36 30 37 import 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'
comment:6 by , 7 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 , 7 years ago
@psuter: I can give you Maintainer access for publishing the new release to pypi:TracMercurial. Do you have a PyPI account?
follow-up: 10 comment:8 by , 7 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 15 15 import unittest 16 16 from datetime import datetime, timedelta 17 17 18 from trac.test import EnvironmentStub, MockRequest, mkdtemp,rmtree18 from trac.test import EnvironmentStub, MockRequest, rmtree 19 19 from trac.util import create_file 20 from trac.util.datefmt import utc20 from trac.util.datefmt import http_date, utc 21 21 from trac.versioncontrol.api import Changeset, DbRepositoryProvider, \ 22 22 InvalidRepository, Node, \ 23 23 NoSuchChangeset, NoSuchNode, \ … … 25 25 from trac.versioncontrol.web_ui.browser import BrowserModule 26 26 from trac.versioncontrol.web_ui.log import LogModule 27 27 28 try: 29 from trac.test import mkdtemp 30 except ImportError: 31 import tempfile 32 def mkdtemp(): 33 return os.path.realpath(tempfile.mkdtemp(prefix='trac-testdir-')) 34 28 35 from tracext.hg.backend import MercurialConnector, MercurialRepository 29 36 30 37 import mercurial.commands … … 71 78 if data: 72 79 hgignore = os.path.join(self.repos_path, '.hgignore') 73 80 create_file(hgignore) 74 ts = datetime(2001, 1, 29, 16, 39, 56 )81 ts = datetime(2001, 1, 29, 16, 39, 56, 0, utc) 75 82 mercurial.commands.commit(self.hgui, self.hgrepo, hgignore, 76 83 message="test", addremove=True, 77 user='Joe', date= ts.isoformat())84 user='Joe', date=http_date(ts)) 78 85 79 86 def _create_commit(self, message, filename): 80 87 fullname = os.path.join(self.repos_path, filename) … … 111 118 create_file(filename, 'commit-%d.txt' % idx) 112 119 mercurial.commands.commit(self.hgui, self.hgrepo, filename, 113 120 message='%d' % idx, addremove=True, 114 user='Joe', date= ts.isoformat())121 user='Joe', date=http_date(ts)) 115 122 self._add_repository() 116 123 repos = self._repomgr.get_repository('hgrepos') 117 124 repos.repo.invalidate() … … 327 334 328 335 class MercurialConnectorTestCase(BaseTestCase): 329 336 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 330 344 def _hg_version_from_system_info(self): 331 345 hg_version = None 332 for name, version in self. env.system_info:346 for name, version in self._get_system_info(): 333 347 if name == 'Mercurial': 334 348 hg_version = version 335 349 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'
follow-ups: 13 18 comment:9 by , 7 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.
follow-up: 11 comment:10 by , 7 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?
follow-up: 15 comment:11 by , 7 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 1246 1246 fc = annotateline[0] 1247 1247 if isinstance(fc, tuple): 1248 1248 fc = fc[0] 1249 elif not isinstance(fc, filectx): 1250 fc = fc.fctx 1249 1251 else: 1250 1252 fc = annotateline.fctx 1251 1253 annotations.append(fc.rev() or '0')
follow-up: 14 comment:12 by , 7 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'
comment:13 by , 7 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
comment:14 by , 7 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].
comment:15 by , 7 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 totracext/hg/tests/backend.py
. However, I think the behavior is weird. Theos.stat_float_times(False)
is automaticaly invoked byimport 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 1246 1246 fc = annotateline[0] 1247 1247 if isinstance(fc, tuple): 1248 1248 fc = fc[0] 1249 elif not isinstance(fc, filectx): 1250 fc = fc.fctx 1249 1251 else: 1250 1252 fc = annotateline.fctx 1251 1253 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:17 by , 7 years ago
The proposed changes look very good to me.
Thanks. Pushed the two commits in mercurial-plugin@a236958adc56:923f81dadc2f.
follow-up: 19 comment:18 by , 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.
comment:19 by , 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.
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?