From 3b873f75ef32c500e69da22dcfc73155414bb6d0 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 4 Jan 2013 18:39:43 +0200 Subject: ComponentTestBase: capability to check files of repo Makes it possible to check that the correct files are present in the working copy of the repo. Signed-off-by: Markus Lehtonen --- tests/component/__init__.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests/component') diff --git a/tests/component/__init__.py b/tests/component/__init__.py index 3aca00c..115f995 100644 --- a/tests/component/__init__.py +++ b/tests/component/__init__.py @@ -116,12 +116,29 @@ class ComponentTestBase(object): self._capture_log(False) @classmethod - def _check_repo_state(cls, repo, current_branch, branches): + def _check_repo_state(cls, repo, current_branch, branches, files=None): """Check that repository is clean and given branches exist""" branch = repo.branch assert branch == current_branch assert repo.is_clean() assert set(repo.get_local_branches()) == set(branches) + if files is not None: + # Get files of the working copy recursively + local = set() + for dirpath, dirnames, filenames in os.walk(repo.path): + # Skip git dir(s) + if '.git' in dirnames: + dirnames.remove('.git') + for filename in filenames: + local.add(os.path.relpath(os.path.join(dirpath, filename), + repo.path)) + for dirname in dirnames: + local.add(os.path.relpath(os.path.join(dirpath, dirname), + repo.path) + '/') + extra = local - set(files) + assert not extra, "Unexpected files in repo: %s" % list(extra) + missing = set(files) - local + assert not missing, "Files missing from repo: %s" % list(missing) def _capture_log(self, capture=True): """ Capture log""" -- cgit v1.2.3