Permalink
Browse files

First tests for versioncontrol.

There is a parent class with some helper methods, and
for now only a few initial tests for SVN.
  • Loading branch information...
1 parent f90b943 commit c9cd11124beaa203f694ae8f2a00750a6bdcecc1 @friedelwolff friedelwolff committed May 1, 2012
Showing with 81 additions and 0 deletions.
  1. +48 −0 translate/storage/versioncontrol/test_helper.py
  2. +33 −0 translate/storage/versioncontrol/test_svn.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+
+import os.path
+import shutil
+
+from translate.storage.versioncontrol import run_command, get_versioned_object
+
+class HelperTest(object):
+
+ def remove_dirs(self, path):
+ if os.path.exists(path):
+ shutil.rmtree(path)
+
+ def get_test_path(self, method):
+ return os.path.realpath("%s_%s" % (self.__class__.__name__, method.__name__))
+
+ def setup_method(self, method):
+ """Allocates a unique self.filename for the method, making sure it doesn't exist"""
+ self.path = self.get_test_path(method)
+ self.co_path = os.path.join(self.path, "checkout")
+ self.remove_dirs(self.path)
+ os.makedirs(self.path)
+ self.setup_repo_and_checkout()
+
+ def setup_repo_and_checkout(self):
+ """Implementations should override this to create a repository and a
+ clone/checkout.
+
+ The repository should be in 'repo'.
+ The checkout/clone should be in 'checkout'.
+ """
+ pass
+
+ def teardown_method(self, method):
+ """Makes sure that if self.filename was created by the method, it is cleaned up"""
+ self.remove_dirs(self.path)
+
+ def create_files(self, files_dict):
+ """Creates file(s) named after the keys, with contents from the values
+ of the dictionary."""
+ for name, content in files_dict.iteritems():
+ assert not os.path.isabs(name)
+ dirs = os.path.dirname(name)
+ if dirs:
+ os.path.makedirs(os.path.join(self.co_path, dirs))
+ f = open(os.path.join(self.co_path, dirs, name), 'w')
+ f.write(content)
+ f.close()
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+
+import os.path
+
+from translate.storage.versioncontrol.test_helper import HelperTest
+from translate.storage.versioncontrol import svn
+from translate.storage.versioncontrol import run_command, get_versioned_object
+
+class TestSVN(HelperTest):
+
+ def setup_repo_and_checkout(self):
+ run_command(["svnadmin", "create", "repo"], cwd=self.path)
+ run_command(["svn", "co", "file:///%s/repo" % self.path, "checkout"], cwd=self.path)
+
+ def test_detection(self):
+ print self.co_path
+ o = get_versioned_object(self.co_path)
+ assert isinstance(o, svn.svn)
+ assert o.location_abs == self.co_path
+
+
+ def test_add(self):
+ o = get_versioned_object(self.co_path)
+ self.create_files({
+ "test1.txt": "First file\n",
+ "test2.txt": "Second file\n",
+ })
+ file_path = os.path.join(self.co_path, "test1.txt")
+ o.add(os.path.join(file_path))
+ o = get_versioned_object(file_path)
+ assert os.path.samefile(o.location_abs, file_path)
+
+ assert o.getcleanfile() == "First file\n"

0 comments on commit c9cd111

Please sign in to comment.