##// END OF EJS Templates
vcs: always return bytes from node.content...
vcs: always return bytes from node.content We will rather have the unicode conversions explicit. Note: Py3 bytes doesn't have .startswith - replace that with a regexp.

File last commit:

r7942:9203621c default
r7942:9203621c default
Show More
test_git.py
844 lines | 37.1 KiB | text/x-python | PythonLexer
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 import datetime
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 import os
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 import sys
Daniel Anderson
Escape shell command parts for Git backend...
r4395 import urllib2
domruf
tests: self.fail is better written as pytest.fail now
r5723
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 import mock
domruf
tests: self.fail is better written as pytest.fail now
r5723 import pytest
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib.vcs.backends.git import GitChangeset, GitRepository
from kallithea.lib.vcs.exceptions import NodeDoesNotExistError, RepositoryError, VCSError
from kallithea.lib.vcs.nodes import DirNode, FileNode, NodeKind, NodeState
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466 from kallithea.model.scm import ScmModel
Marc Abramowitz
tests: avoid executing tests in base classes...
r5051 from kallithea.tests.vcs.base import _BackendTestMixin
Branko Majic
tests: fix TESTS_TMP_PATH naming
r7041 from kallithea.tests.vcs.conf import TEST_GIT_REPO, TEST_GIT_REPO_CLONE, TESTS_TMP_PATH, get_new_dir
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 class TestGitRepository(object):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def __check_for_existing_repo(self):
if os.path.exists(TEST_GIT_REPO_CLONE):
domruf
tests: self.fail is better written as pytest.fail now
r5723 pytest.fail('Cannot test git clone repo as location %s already '
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 'exists. You should manually remove it first.'
% TEST_GIT_REPO_CLONE)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 def setup_method(self):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.repo = GitRepository(TEST_GIT_REPO)
def test_wrong_repo_path(self):
Branko Majic
tests: fix TESTS_TMP_PATH naming
r7041 wrong_repo_path = os.path.join(TESTS_TMP_PATH, 'errorrepo')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(RepositoryError):
GitRepository(wrong_repo_path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Daniel Anderson
Escape shell command parts for Git backend...
r4395 def test_git_cmd_injection(self):
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 repo_inject_path = TEST_GIT_REPO + '; echo "Cake";'
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(urllib2.URLError):
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 # Should fail because URL will contain the parts after ; too
Mads Kiilerich
tests: fix some pyflakes warnings for vcs
r7039 GitRepository(get_new_dir('injection-repo'), src_url=repo_inject_path, update_after_clone=True, create=True)
Daniel Anderson
Escape shell command parts for Git backend...
r4395
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(RepositoryError):
Daniel Anderson
Escape shell command parts for Git backend...
r4395 # Should fail on direct clone call, which as of this writing does not happen outside of class
clone_fail_repo = GitRepository(get_new_dir('injection-repo'), create=True)
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 clone_fail_repo.clone(repo_inject_path, update_after_clone=True,)
Daniel Anderson
Escape shell command parts for Git backend...
r4395
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 # Verify correct quoting of evil characters that should work on posix file systems
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 if sys.platform == 'win32':
# windows does not allow '"' in dir names
domruf
tests: fix Git on Windows sometimes failing on ' or ` in file:/// URLs...
r5758 # and some versions of the git client don't like ` and '
tricky_path = get_new_dir("tricky-path-repo-$")
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 else:
tricky_path = get_new_dir("tricky-path-repo-$'\"`")
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 successfully_cloned = GitRepository(tricky_path, src_url=TEST_GIT_REPO, update_after_clone=True, create=True)
Daniel Anderson
Escape shell command parts for Git backend...
r4395 # Repo should have been created
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert not successfully_cloned._repo.bare
Daniel Anderson
Escape shell command parts for Git backend...
r4395
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 if sys.platform == 'win32':
# windows does not allow '"' in dir names
domruf
tests: fix Git on Windows sometimes failing on ' or ` in file:/// URLs...
r5758 # and some versions of the git client don't like ` and '
tricky_path_2 = get_new_dir("tricky-path-2-repo-$")
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 else:
tricky_path_2 = get_new_dir("tricky-path-2-repo-$'\"`")
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 successfully_cloned2 = GitRepository(tricky_path_2, src_url=tricky_path, bare=True, create=True)
# Repo should have been created and thus used correct quoting for clone
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert successfully_cloned2._repo.bare
Daniel Anderson
Escape shell command parts for Git backend...
r4395
Mads Kiilerich
git: rework tests to use local repos instead of accessing github ... and add missing quote found by this
r4396 # Should pass because URL has been properly quoted
successfully_cloned.pull(tricky_path_2)
successfully_cloned2.fetch(tricky_path)
Daniel Anderson
Escape shell command parts for Git backend...
r4395
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 def test_repo_create_with_spaces_in_path(self):
repo_path = get_new_dir("path with spaces")
repo = GitRepository(repo_path, src_url=None, bare=True, create=True)
# Repo should have been created
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert repo._repo.bare
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def test_repo_clone(self):
self.__check_for_existing_repo()
repo = GitRepository(TEST_GIT_REPO)
repo_clone = GitRepository(TEST_GIT_REPO_CLONE,
src_url=TEST_GIT_REPO, create=True, update_after_clone=True)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(repo.revisions) == len(repo_clone.revisions)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # Checking hashes of changesets should be enough
for changeset in repo.get_changesets():
raw_id = changeset.raw_id
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert raw_id == repo_clone.get_changeset(raw_id).raw_id
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181 def test_repo_clone_with_spaces_in_path(self):
repo_path = get_new_dir("path with spaces")
successfully_cloned = GitRepository(repo_path, src_url=TEST_GIT_REPO, update_after_clone=True, create=True)
# Repo should have been created
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert not successfully_cloned._repo.bare
Matthias Zilk
git: fix test_git_cmd_injection on windows, add tests for path with spaces
r5181
successfully_cloned.pull(TEST_GIT_REPO)
self.repo.fetch(repo_path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def test_repo_clone_without_create(self):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(RepositoryError):
GitRepository(TEST_GIT_REPO_CLONE + '_wo_create', src_url=TEST_GIT_REPO)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_repo_clone_with_update(self):
repo = GitRepository(TEST_GIT_REPO)
clone_path = TEST_GIT_REPO_CLONE + '_with_update'
repo_clone = GitRepository(clone_path,
create=True, src_url=TEST_GIT_REPO, update_after_clone=True)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(repo.revisions) == len(repo_clone.revisions)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Lars Kruse
codingstyle: trivial whitespace fixes...
r6789 # check if current workdir was updated
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 fpath = os.path.join(clone_path, 'MANIFEST.in')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert os.path.isfile(fpath) == True, 'Repo was cloned and updated but file %s could not be found' % fpath
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_repo_clone_without_update(self):
repo = GitRepository(TEST_GIT_REPO)
clone_path = TEST_GIT_REPO_CLONE + '_without_update'
repo_clone = GitRepository(clone_path,
create=True, src_url=TEST_GIT_REPO, update_after_clone=False)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(repo.revisions) == len(repo_clone.revisions)
Lars Kruse
codingstyle: trivial whitespace fixes...
r6789 # check if current workdir was *NOT* updated
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 fpath = os.path.join(clone_path, 'MANIFEST.in')
# Make sure it's not bare repo
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert not repo_clone._repo.bare
assert os.path.isfile(fpath) == False, 'Repo was cloned and updated but file %s was found' % fpath
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_repo_clone_into_bare_repo(self):
repo = GitRepository(TEST_GIT_REPO)
clone_path = TEST_GIT_REPO_CLONE + '_bare.git'
repo_clone = GitRepository(clone_path, create=True,
src_url=repo.path, bare=True)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert repo_clone._repo.bare
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_create_repo_is_not_bare_by_default(self):
repo = GitRepository(get_new_dir('not-bare-by-default'), create=True)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert not repo._repo.bare
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_create_bare_repo(self):
repo = GitRepository(get_new_dir('bare-repo'), create=True, bare=True)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert repo._repo.bare
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_revisions(self):
# there are 112 revisions (by now)
# so we can assume they would be available from now on
subset = set([
'c1214f7e79e02fc37156ff215cd71275450cffc3',
'38b5fe81f109cb111f549bfe9bb6b267e10bc557',
'fa6600f6848800641328adbf7811fd2372c02ab2',
'102607b09cdd60e2793929c4f90478be29f85a17',
'49d3fd156b6f7db46313fac355dca1a0b94a0017',
'2d1028c054665b962fa3d307adfc923ddd528038',
'd7e0d30fbcae12c90680eb095a4f5f02505ce501',
'ff7ca51e58c505fec0dd2491de52c622bb7a806b',
'dd80b0f6cf5052f17cc738c2951c4f2070200d7f',
'8430a588b43b5d6da365400117c89400326e7992',
'd955cd312c17b02143c04fa1099a352b04368118',
'f67b87e5c629c2ee0ba58f85197e423ff28d735b',
'add63e382e4aabc9e1afdc4bdc24506c269b7618',
'f298fe1189f1b69779a4423f40b48edf92a703fc',
'bd9b619eb41994cac43d67cf4ccc8399c1125808',
'6e125e7c890379446e98980d8ed60fba87d0f6d1',
'd4a54db9f745dfeba6933bf5b1e79e15d0af20bd',
'0b05e4ed56c802098dfc813cbe779b2f49e92500',
'191caa5b2c81ed17c0794bf7bb9958f4dcb0b87e',
'45223f8f114c64bf4d6f853e3c35a369a6305520',
'ca1eb7957a54bce53b12d1a51b13452f95bc7c7e',
'f5ea29fc42ef67a2a5a7aecff10e1566699acd68',
'27d48942240f5b91dfda77accd2caac94708cc7d',
'622f0eb0bafd619d2560c26f80f09e3b0b0d78af',
'e686b958768ee96af8029fe19c6050b1a8dd3b2b'])
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert subset.issubset(set(self.repo.revisions))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_slicing(self):
Lars Kruse
codingstyle: trivial whitespace fixes...
r6789 # 4 1 5 10 95
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 for sfrom, sto, size in [(0, 4, 4), (1, 2, 1), (10, 15, 5),
(10, 20, 10), (5, 100, 95)]:
revs = list(self.repo[sfrom:sto])
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(revs) == size
assert revs[0] == self.repo.get_changeset(sfrom)
assert revs[-1] == self.repo.get_changeset(sto - 1)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_branches(self):
# TODO: Need more tests here
# Removed (those are 'remotes' branches for cloned repo)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 #assert 'master' in self.repo.branches
#assert 'gittree' in self.repo.branches
#assert 'web-branch' in self.repo.branches
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 for name, id in self.repo.branches.items():
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert isinstance(self.repo.get_changeset(id), GitChangeset)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_tags(self):
# TODO: Need more tests here
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert 'v0.1.1' in self.repo.tags
assert 'v0.1.2' in self.repo.tags
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 for name, id in self.repo.tags.items():
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert isinstance(self.repo.get_changeset(id), GitChangeset)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def _test_single_changeset_cache(self, revision):
chset = self.repo.get_changeset(revision)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert revision in self.repo.changesets
assert chset is self.repo.changesets[revision]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_initial_changeset(self):
id = self.repo.revisions[0]
init_chset = self.repo.get_changeset(id)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert init_chset.message == 'initial import\n'
assert init_chset.author == 'Marcin Kuzminski <marcin@python-blog.com>'
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 for path in ('vcs/__init__.py',
'vcs/backends/BaseRepository.py',
'vcs/backends/__init__.py'):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert isinstance(init_chset.get_node(path), FileNode)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 for path in ('', 'vcs', 'vcs/backends'):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert isinstance(init_chset.get_node(path), DirNode)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(NodeDoesNotExistError):
init_chset.get_node(path='foobar')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
node = init_chset.get_node('vcs/')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert hasattr(node, 'kind')
assert node.kind == NodeKind.DIR
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
node = init_chset.get_node('vcs')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert hasattr(node, 'kind')
assert node.kind == NodeKind.DIR
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
node = init_chset.get_node('vcs/__init__.py')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert hasattr(node, 'kind')
assert node.kind == NodeKind.FILE
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_not_existing_changeset(self):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(RepositoryError):
self.repo.get_changeset('f' * 40)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_changeset10(self):
chset10 = self.repo.get_changeset(self.repo.revisions[9])
Lars Kruse
codingstyle: replace upper-case variable names with lower-case ones...
r6790 readme = """===
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 VCS
===
Various Version Control System management abstraction layer for Python.
Introduction
------------
TODO: To be written...
"""
node = chset10.get_node('README.rst')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert node.kind == NodeKind.FILE
assert node.content == readme
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 class TestGitChangeset(object):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 def setup_method(self):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.repo = GitRepository(TEST_GIT_REPO)
def test_default_changeset(self):
tip = self.repo.get_changeset()
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert tip == self.repo.get_changeset(None)
assert tip == self.repo.get_changeset('tip')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_root_node(self):
tip = self.repo.get_changeset()
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert tip.root is tip.get_node('')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_lazy_fetch(self):
"""
Test if changeset's nodes expands and are cached as we walk through
the revision. This test is somewhat hard to write as order of tests
is a key here. Written by running command after command in a shell.
"""
Lars Kruse
codingstyle: rename variable "hex" (conflicting with builtin)
r6795 commit_id = '2a13f185e4525f9d4b59882791a2d397b90d5ddc'
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert commit_id in self.repo.revisions
Lars Kruse
codingstyle: rename variable "hex" (conflicting with builtin)
r6795 chset = self.repo.get_changeset(commit_id)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(chset.nodes) == 0
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 root = chset.root
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(chset.nodes) == 1
assert len(root.nodes) == 8
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # accessing root.nodes updates chset.nodes
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(chset.nodes) == 9
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
docs = root.get_node('docs')
# we haven't yet accessed anything new as docs dir was already cached
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(chset.nodes) == 9
assert len(docs.nodes) == 8
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # accessing docs.nodes updates chset.nodes
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert len(chset.nodes) == 17
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert docs is chset.get_node('docs')
assert docs is root.nodes[0]
assert docs is root.dirs[0]
assert docs is chset.get_node('docs')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_nodes_with_changeset(self):
Lars Kruse
codingstyle: rename variable "hex" (conflicting with builtin)
r6795 commit_id = '2a13f185e4525f9d4b59882791a2d397b90d5ddc'
chset = self.repo.get_changeset(commit_id)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 root = chset.root
docs = root.get_node('docs')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert docs is chset.get_node('docs')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 api = docs.get_node('api')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert api is chset.get_node('docs/api')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 index = api.get_node('index.rst')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert index is chset.get_node('docs/api/index.rst')
assert index is chset.get_node('docs') \
.get_node('api') \
.get_node('index.rst')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_branch_and_tags(self):
Mads Kiilerich
tests: enable disabled Git branch tests, with comments that the current results seem wrong
r7066 # Those tests seem to show wrong results:
# in Git, only heads have a branch - most changesets don't
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 rev0 = self.repo.revisions[0]
chset0 = self.repo.get_changeset(rev0)
Mads Kiilerich
tests: enable disabled Git branch tests, with comments that the current results seem wrong
r7066 assert chset0.branch is None # should be 'master'?
Mads Kiilerich
vcs: introduce 'branches' attribute on changesets, making it possible for Git to show multiple branches for a changeset...
r7067 assert chset0.branches == [] # should be 'master'?
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert chset0.tags == []
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
rev10 = self.repo.revisions[10]
chset10 = self.repo.get_changeset(rev10)
Mads Kiilerich
tests: enable disabled Git branch tests, with comments that the current results seem wrong
r7066 assert chset10.branch is None # should be 'master'?
Mads Kiilerich
vcs: introduce 'branches' attribute on changesets, making it possible for Git to show multiple branches for a changeset...
r7067 assert chset10.branches == [] # should be 'master'?
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert chset10.tags == []
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
rev44 = self.repo.revisions[44]
chset44 = self.repo.get_changeset(rev44)
Mads Kiilerich
tests: enable disabled Git branch tests, with comments that the current results seem wrong
r7066 assert chset44.branch is None # should be 'web-branch'?
Mads Kiilerich
vcs: introduce 'branches' attribute on changesets, making it possible for Git to show multiple branches for a changeset...
r7067 assert chset44.branches == [] # should be 'web-branch'?
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
tip = self.repo.get_changeset('tip')
Mads Kiilerich
tests: enable disabled Git branch tests, with comments that the current results seem wrong
r7066 assert 'tip' not in tip.tags # it should be?
assert not tip.tags # how it is!
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def _test_slices(self, limit, offset):
count = self.repo.count()
changesets = self.repo.get_changesets(limit=limit, offset=offset)
idx = 0
for changeset in changesets:
rev = offset + idx
idx += 1
rev_id = self.repo.revisions[rev]
if idx > limit:
domruf
tests: self.fail is better written as pytest.fail now
r5723 pytest.fail("Exceeded limit already (getting revision %s, "
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 "there are %s total revisions, offset=%s, limit=%s)"
% (rev_id, count, offset, limit))
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert changeset == self.repo.get_changeset(rev_id)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 result = list(self.repo.get_changesets(limit=limit, offset=offset))
start = offset
end = limit and offset + limit or None
sliced = list(self.repo[start:end])
domruf
tests: self.fail is better written as pytest.fail now
r5723 pytest.failUnlessEqual(result, sliced,
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 msg="Comparison failed for limit=%s, offset=%s"
"(get_changeset returned: %s and sliced: %s"
% (limit, offset, result, sliced))
def _test_file_size(self, revision, path, size):
node = self.repo.get_changeset(revision).get_node(path)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert node.is_file()
assert node.size == size
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_file_size(self):
to_check = (
('c1214f7e79e02fc37156ff215cd71275450cffc3',
'vcs/backends/BaseRepository.py', 502),
('d7e0d30fbcae12c90680eb095a4f5f02505ce501',
'vcs/backends/hg.py', 854),
('6e125e7c890379446e98980d8ed60fba87d0f6d1',
'setup.py', 1068),
('d955cd312c17b02143c04fa1099a352b04368118',
'vcs/backends/base.py', 2921),
('ca1eb7957a54bce53b12d1a51b13452f95bc7c7e',
'vcs/backends/base.py', 3936),
('f50f42baeed5af6518ef4b0cb2f1423f3851a941',
'vcs/backends/base.py', 6189),
)
for revision, path, size in to_check:
self._test_file_size(revision, path, size)
domruf
tests: add repository size tests
r5770 def _test_dir_size(self, revision, path, size):
node = self.repo.get_changeset(revision).get_node(path)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert node.size == size
domruf
tests: add repository size tests
r5770
def test_dir_size(self):
to_check = (
('5f2c6ee195929b0be80749243c18121c9864a3b3', '/', 674076),
('7ab37bc680b4aa72c34d07b230c866c28e9fc204', '/', 674049),
('6892503fb8f2a552cef5f4d4cc2cdbd13ae1cd2f', '/', 671830),
)
for revision, path, size in to_check:
self._test_dir_size(revision, path, size)
def test_repo_size(self):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert self.repo.size == 674076
domruf
tests: add repository size tests
r5770
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def test_file_history(self):
# we can only check if those revisions are present in the history
# as we cannot update this test every time file is changed
files = {
'setup.py': [
'54386793436c938cff89326944d4c2702340037d',
'51d254f0ecf5df2ce50c0b115741f4cf13985dab',
'998ed409c795fec2012b1c0ca054d99888b22090',
'5e0eb4c47f56564395f76333f319d26c79e2fb09',
'0115510b70c7229dbc5dc49036b32e7d91d23acd',
'7cb3fd1b6d8c20ba89e2264f1c8baebc8a52d36e',
'2a13f185e4525f9d4b59882791a2d397b90d5ddc',
'191caa5b2c81ed17c0794bf7bb9958f4dcb0b87e',
'ff7ca51e58c505fec0dd2491de52c622bb7a806b',
],
'vcs/nodes.py': [
'33fa3223355104431402a888fa77a4e9956feb3e',
'fa014c12c26d10ba682fadb78f2a11c24c8118e1',
'e686b958768ee96af8029fe19c6050b1a8dd3b2b',
'ab5721ca0a081f26bf43d9051e615af2cc99952f',
'c877b68d18e792a66b7f4c529ea02c8f80801542',
'4313566d2e417cb382948f8d9d7c765330356054',
'6c2303a793671e807d1cfc70134c9ca0767d98c2',
'54386793436c938cff89326944d4c2702340037d',
'54000345d2e78b03a99d561399e8e548de3f3203',
'1c6b3677b37ea064cb4b51714d8f7498f93f4b2b',
'2d03ca750a44440fb5ea8b751176d1f36f8e8f46',
'2a08b128c206db48c2f0b8f70df060e6db0ae4f8',
'30c26513ff1eb8e5ce0e1c6b477ee5dc50e2f34b',
'ac71e9503c2ca95542839af0ce7b64011b72ea7c',
'12669288fd13adba2a9b7dd5b870cc23ffab92d2',
'5a0c84f3e6fe3473e4c8427199d5a6fc71a9b382',
'12f2f5e2b38e6ff3fbdb5d722efed9aa72ecb0d5',
'5eab1222a7cd4bfcbabc218ca6d04276d4e27378',
'f50f42baeed5af6518ef4b0cb2f1423f3851a941',
'd7e390a45f6aa96f04f5e7f583ad4f867431aa25',
'f15c21f97864b4f071cddfbf2750ec2e23859414',
'e906ef056cf539a4e4e5fc8003eaf7cf14dd8ade',
'ea2b108b48aa8f8c9c4a941f66c1a03315ca1c3b',
'84dec09632a4458f79f50ddbbd155506c460b4f9',
'0115510b70c7229dbc5dc49036b32e7d91d23acd',
'2a13f185e4525f9d4b59882791a2d397b90d5ddc',
'3bf1c5868e570e39569d094f922d33ced2fa3b2b',
'b8d04012574729d2c29886e53b1a43ef16dd00a1',
'6970b057cffe4aab0a792aa634c89f4bebf01441',
'dd80b0f6cf5052f17cc738c2951c4f2070200d7f',
'ff7ca51e58c505fec0dd2491de52c622bb7a806b',
],
'vcs/backends/git.py': [
'4cf116ad5a457530381135e2f4c453e68a1b0105',
'9a751d84d8e9408e736329767387f41b36935153',
'cb681fb539c3faaedbcdf5ca71ca413425c18f01',
'428f81bb652bcba8d631bce926e8834ff49bdcc6',
'180ab15aebf26f98f714d8c68715e0f05fa6e1c7',
'2b8e07312a2e89e92b90426ab97f349f4bce2a3a',
'50e08c506174d8645a4bb517dd122ac946a0f3bf',
'54000345d2e78b03a99d561399e8e548de3f3203',
],
}
for path, revs in files.items():
node = self.repo.get_changeset(revs[0]).get_node(path)
node_revs = [chset.raw_id for chset in node.history]
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert set(revs).issubset(set(node_revs)), "We assumed that %s is subset of revisions for which file %s " \
"has been changed, and history of that node returned: %s" \
% (revs, path, node_revs)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_file_annotate(self):
files = {
'vcs/backends/__init__.py': {
'c1214f7e79e02fc37156ff215cd71275450cffc3': {
'lines_no': 1,
'changesets': [
'c1214f7e79e02fc37156ff215cd71275450cffc3',
],
},
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647': {
'lines_no': 21,
'changesets': [
'49d3fd156b6f7db46313fac355dca1a0b94a0017',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
],
},
'e29b67bd158580fc90fc5e9111240b90e6e86064': {
'lines_no': 32,
'changesets': [
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'5eab1222a7cd4bfcbabc218ca6d04276d4e27378',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'54000345d2e78b03a99d561399e8e548de3f3203',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'78c3f0c23b7ee935ec276acb8b8212444c33c396',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'2a13f185e4525f9d4b59882791a2d397b90d5ddc',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'78c3f0c23b7ee935ec276acb8b8212444c33c396',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'992f38217b979d0b0987d0bae3cc26dac85d9b19',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
'16fba1ae9334d79b66d7afed2c2dfbfa2ae53647',
],
},
},
}
for fname, revision_dict in files.items():
for rev, data in revision_dict.items():
cs = self.repo.get_changeset(rev)
l1_1 = [x[1] for x in cs.get_file_annotate(fname)]
l1_2 = [x[2]().raw_id for x in cs.get_file_annotate(fname)]
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert l1_1 == l1_2
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 l1 = l1_1
l2 = files[fname][rev]['changesets']
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert l1 == l2, "The lists of revision for %s@rev %s" \
"from annotation list should match each other, " \
"got \n%s \nvs \n%s " % (fname, rev, l1, l2)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_files_state(self):
"""
Tests state of FileNodes.
"""
Mads Kiilerich
cleanup: consistent space before line continuation backslash
r5585 node = self.repo \
.get_changeset('e6ea6d16e2f26250124a1f4b4fe37a912f9d86a0') \
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 .get_node('vcs/utils/diffs.py')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert node.state, NodeState.ADDED
assert node.added
assert not node.changed
assert not node.not_changed
assert not node.removed
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
cleanup: consistent space before line continuation backslash
r5585 node = self.repo \
.get_changeset('33fa3223355104431402a888fa77a4e9956feb3e') \
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 .get_node('.hgignore')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert node.state, NodeState.CHANGED
assert not node.added
assert node.changed
assert not node.not_changed
assert not node.removed
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
cleanup: consistent space before line continuation backslash
r5585 node = self.repo \
.get_changeset('e29b67bd158580fc90fc5e9111240b90e6e86064') \
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 .get_node('setup.py')
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert node.state, NodeState.NOT_CHANGED
assert not node.added
assert not node.changed
assert node.not_changed
assert not node.removed
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
# If node has REMOVED state then trying to fetch it would raise
# ChangesetError exception
chset = self.repo.get_changeset(
'fa6600f6848800641328adbf7811fd2372c02ab2')
path = 'vcs/backends/BaseRepository.py'
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(NodeDoesNotExistError):
chset.get_node(path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # but it would be one of ``removed`` (changeset's attribute)
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert path in [rf.path for rf in chset.removed]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
chset = self.repo.get_changeset(
'54386793436c938cff89326944d4c2702340037d')
changed = ['setup.py', 'tests/test_nodes.py', 'vcs/backends/hg.py',
'vcs/nodes.py']
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert set(changed) == set([f.path for f in chset.changed])
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_commit_message_is_unicode(self):
for cs in self.repo:
Mads Kiilerich
cleanup: use isinstance instead of comparing types...
r7884 assert isinstance(cs.message, unicode)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_changeset_author_is_unicode(self):
for cs in self.repo:
Mads Kiilerich
cleanup: use isinstance instead of comparing types...
r7884 assert isinstance(cs.author, unicode)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
vcs: always return bytes from node.content...
r7942 def test_repo_files_content_is_bytes(self):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 changeset = self.repo.get_changeset()
for node in changeset.get_node('/'):
if node.is_file():
Mads Kiilerich
vcs: always return bytes from node.content...
r7942 assert isinstance(node.content, bytes)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_wrong_path(self):
# There is 'setup.py' in the root dir but not there:
path = 'foo/bar/setup.py'
tip = self.repo.get_changeset()
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 with pytest.raises(VCSError):
tip.get_node(path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_author_email(self):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert 'marcin@python-blog.com' == self.repo.get_changeset('c1214f7e79e02fc37156ff215cd71275450cffc3').author_email
assert 'lukasz.balcerzak@python-center.pl' == self.repo.get_changeset('ff7ca51e58c505fec0dd2491de52c622bb7a806b').author_email
assert '' == self.repo.get_changeset('8430a588b43b5d6da365400117c89400326e7992').author_email
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_author_username(self):
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert 'Marcin Kuzminski' == self.repo.get_changeset('c1214f7e79e02fc37156ff215cd71275450cffc3').author_name
assert 'Lukasz Balcerzak' == self.repo.get_changeset('ff7ca51e58c505fec0dd2491de52c622bb7a806b').author_name
assert 'marcink none@none' == self.repo.get_changeset('8430a588b43b5d6da365400117c89400326e7992').author_name
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 class TestGitSpecificWithRepo(_BackendTestMixin):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 backend_alias = 'git'
@classmethod
def _get_commits(cls):
return [
{
'message': 'Initial',
'author': 'Joe Doe <joe.doe@example.com>',
'date': datetime.datetime(2010, 1, 1, 20),
'added': [
FileNode('foobar/static/js/admin/base.js', content='base'),
FileNode('foobar/static/admin', content='admin',
Mads Kiilerich
py3: use explicit octal literals...
r7890 mode=0o120000), # this is a link
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 FileNode('foo', content='foo'),
],
},
{
'message': 'Second',
'author': 'Joe Doe <joe.doe@example.com>',
'date': datetime.datetime(2010, 1, 1, 22),
'added': [
FileNode('foo2', content='foo2'),
],
},
]
def test_paths_slow_traversing(self):
cs = self.repo.get_changeset()
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert cs.get_node('foobar').get_node('static').get_node('js').get_node('admin').get_node('base.js').content == 'base'
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_paths_fast_traversing(self):
cs = self.repo.get_changeset()
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert cs.get_node('foobar/static/js/admin/base.js').content == 'base'
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_workdir_get_branch(self):
Mads Kiilerich
git: run external commands as list of strings so we really get correct quoting (Issue #135)...
r5182 self.repo.run_git_command(['checkout', '-b', 'production'])
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # Regression test: one of following would fail if we don't check
# .git/HEAD file
Mads Kiilerich
git: run external commands as list of strings so we really get correct quoting (Issue #135)...
r5182 self.repo.run_git_command(['checkout', 'production'])
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert self.repo.workdir.get_branch() == 'production'
Mads Kiilerich
git: run external commands as list of strings so we really get correct quoting (Issue #135)...
r5182 self.repo.run_git_command(['checkout', 'master'])
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert self.repo.workdir.get_branch() == 'master'
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_get_diff_runs_git_command_with_hashes(self):
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.repo.get_diff(0, 1)
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Mads Kiilerich
git: run external commands as list of strings so we really get correct quoting (Issue #135)...
r5182 ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(0), self.repo._get_revision(1)], cwd=self.repo.path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_get_diff_runs_git_command_with_str_hashes(self):
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.repo.get_diff(self.repo.EMPTY_CHANGESET, 1)
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Mads Kiilerich
git: run external commands as list of strings so we really get correct quoting (Issue #135)...
r5182 ['show', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(1)], cwd=self.repo.path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def test_get_diff_runs_git_command_with_path_if_its_given(self):
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 self.repo.get_diff(0, 1, 'foo')
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Mads Kiilerich
git: run external commands as list of strings so we really get correct quoting (Issue #135)...
r5182 ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 def test_get_diff_does_not_sanitize_valid_context(self):
almost_overflowed_long_int = 2**31-1
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 self.repo.get_diff(0, 1, 'foo', context=almost_overflowed_long_int)
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 ['diff', '-U' + str(almost_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path)
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049
def test_get_diff_sanitizes_overflowing_context(self):
overflowed_long_int = 2**31
sanitized_overflowed_long_int = overflowed_long_int-1
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 self.repo.get_diff(0, 1, 'foo', context=overflowed_long_int)
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 ['diff', '-U' + str(sanitized_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path)
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049
def test_get_diff_does_not_sanitize_zero_context(self):
zero_context = 0
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 self.repo.get_diff(0, 1, 'foo', context=zero_context)
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 ['diff', '-U' + str(zero_context), '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path)
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049
def test_get_diff_sanitizes_negative_context(self):
negative_context = -10
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command = mock.Mock(return_value=(b'', b''))
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 self.repo.get_diff(0, 1, 'foo', context=negative_context)
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._run_git_command.assert_called_once_with(
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049 ['diff', '-U0', '--full-index', '--binary', '-p', '-M', '--abbrev=40',
Mads Kiilerich
vcs: change get_diff to use _run_git_command directly...
r7936 self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path)
Branko Majic
vcs: sanitize diff context values (Issue #306)...
r7049
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 class TestGitRegression(_BackendTestMixin):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 backend_alias = 'git'
@classmethod
def _get_commits(cls):
return [
{
'message': 'Initial',
'author': 'Joe Doe <joe.doe@example.com>',
'date': datetime.datetime(2010, 1, 1, 20),
'added': [
FileNode('bot/__init__.py', content='base'),
FileNode('bot/templates/404.html', content='base'),
FileNode('bot/templates/500.html', content='base'),
],
},
{
'message': 'Second',
'author': 'Joe Doe <joe.doe@example.com>',
'date': datetime.datetime(2010, 1, 1, 22),
'added': [
FileNode('bot/build/migrations/1.py', content='foo2'),
FileNode('bot/build/migrations/2.py', content='foo2'),
FileNode('bot/build/static/templates/f.html', content='foo2'),
FileNode('bot/build/static/templates/f1.html', content='foo2'),
FileNode('bot/build/templates/err.html', content='foo2'),
FileNode('bot/build/templates/err2.html', content='foo2'),
],
},
]
def test_similar_paths(self):
cs = self.repo.get_changeset()
Lars Kruse
codingstyle: trivial whitespace fixes...
r6789 paths = lambda *n: [x.path for x in n]
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert paths(*cs.get_nodes('bot')) == ['bot/build', 'bot/templates', 'bot/__init__.py']
assert paths(*cs.get_nodes('bot/build')) == ['bot/build/migrations', 'bot/build/static', 'bot/build/templates']
assert paths(*cs.get_nodes('bot/build/static')) == ['bot/build/static/templates']
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # this get_nodes below causes troubles !
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert paths(*cs.get_nodes('bot/build/static/templates')) == ['bot/build/static/templates/f.html', 'bot/build/static/templates/f1.html']
assert paths(*cs.get_nodes('bot/build/templates')) == ['bot/build/templates/err.html', 'bot/build/templates/err2.html']
assert paths(*cs.get_nodes('bot/templates/')) == ['bot/templates/404.html', 'bot/templates/500.html']
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 class TestGitHooks(object):
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466 """
Tests related to hook functionality of Git repositories.
"""
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 def setup_method(self):
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466 # For each run we want a fresh repo.
self.repo_directory = get_new_dir("githookrepo")
self.repo = GitRepository(self.repo_directory, create=True)
# Create a dictionary where keys are hook names, and values are paths to
# them. Deduplicates code in tests a bit.
self.hook_directory = self.repo.get_hook_location()
Mads Kiilerich
tests: fix Python 2.6 compatibility - issue introduced in 28d9e9f0ae4e
r5955 self.kallithea_hooks = dict((h, os.path.join(self.hook_directory, h)) for h in ("pre-receive", "post-receive"))
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466
def test_hooks_created_if_missing(self):
"""
Tests if hooks are installed in repository if they are missing.
"""
for hook, hook_path in self.kallithea_hooks.iteritems():
if os.path.exists(hook_path):
os.remove(hook_path)
ScmModel().install_git_hooks(repo=self.repo)
for hook, hook_path in self.kallithea_hooks.iteritems():
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert os.path.exists(hook_path)
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466
def test_kallithea_hooks_updated(self):
"""
Tests if hooks are updated if they are Kallithea hooks already.
"""
for hook, hook_path in self.kallithea_hooks.iteritems():
with open(hook_path, "w") as f:
f.write("KALLITHEA_HOOK_VER=0.0.0\nJUST_BOGUS")
ScmModel().install_git_hooks(repo=self.repo)
for hook, hook_path in self.kallithea_hooks.iteritems():
with open(hook_path) as f:
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert "JUST_BOGUS" not in f.read()
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466
def test_custom_hooks_untouched(self):
"""
Tests if hooks are left untouched if they are not Kallithea hooks.
"""
for hook, hook_path in self.kallithea_hooks.iteritems():
with open(hook_path, "w") as f:
f.write("#!/bin/bash\n#CUSTOM_HOOK")
ScmModel().install_git_hooks(repo=self.repo)
for hook, hook_path in self.kallithea_hooks.iteritems():
with open(hook_path) as f:
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert "CUSTOM_HOOK" in f.read()
Branko Majic
tests: add tests for c3d83238afa1 and git hook installation in general
r5466
def test_custom_hooks_forced_update(self):
"""
Tests if hooks are forcefully updated even though they are custom hooks.
"""
for hook, hook_path in self.kallithea_hooks.iteritems():
with open(hook_path, "w") as f:
f.write("#!/bin/bash\n#CUSTOM_HOOK")
ScmModel().install_git_hooks(repo=self.repo, force_create=True)
for hook, hook_path in self.kallithea_hooks.iteritems():
with open(hook_path) as f:
Branko Majic
tests: update _BackendTestMixin to py.test and convert tests using it from self.assert to plain py.test style asserts
r7046 assert "KALLITHEA_HOOK_VER" in f.read()