diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-03-04 19:10:37 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2017-03-04 19:12:55 +0100 |
commit | 2e1e99bdb18368de7cb30623c4381baa076f4307 (patch) | |
tree | 094631f60852438a36e987b709cfab3137897f4f /tests | |
parent | d4d4120ed6362e15f55d83525515c959713ff4ba (diff) |
Auto add edited files to git
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_collection.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_collection.py b/tests/test_collection.py index 265db09..e17e044 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -4,6 +4,7 @@ import shutil import tempfile import unittest +import git import ruamel.yaml import lesana @@ -264,6 +265,39 @@ class testCollectionCreation(unittest.TestCase): mset = collection._enquire.get_mset(0, 10) self.assertEqual(mset.get_matches_estimated(), 0) + def _find_file_in_git_index(self, fname, index): + found = False + for (path, stage) in index.entries: + if fname in path: + found = True + break + return found + + def test_git_adding(self): + tmpdir = tempfile.mkdtemp() + shutil.copy('tests/data/simple/settings.yaml', tmpdir) + shutil.copytree( + 'tests/data/simple/items', + os.path.join(tmpdir, 'items'), + ) + collection = lesana.Collection.init(tmpdir) + fname = '11189ee47ddf4796b718a483b379f976.yaml' + repo = git.Repo(tmpdir) + # By default, this collection doesn't have any git entry in the + # settings (but there is a repo) + collection.git_add_files([os.path.join(collection.itemdir, fname)]) + self.assertFalse(self._find_file_in_git_index(fname, repo.index)) + # Then we set it to false + collection.settings['git'] = False + collection.git_add_files([os.path.join(collection.itemdir, fname)]) + self.assertFalse(self._find_file_in_git_index(fname, repo.index)) + # And only when it's set to true we should find the file in the + # staging area + collection.settings['git'] = True + collection.git_add_files([os.path.join(collection.itemdir, fname)]) + self.assertTrue(self._find_file_in_git_index(fname, repo.index)) + shutil.rmtree(tmpdir) + if __name__ == '__main__': unittest.main() |