class Repository: path = None adapter = None scm_dirs = [".git"] def __init__(self, path): if not os.path.exists(path) or not os.path.isdir(path): raise RepositoryPathInvalid("Path doesn't exists or isn't a directory (%s)\n" % path) try: scm = (set(self.scm_dirs) & set(os.listdir(path))).pop() except KeyError: raise RepositoryAdapterNotFound("Can't define repository type") else: self.path = path if scm == ".git": self.adapter = Git(path) def get_scm(self): """Get scm used as string.""" if self.adapter is None: return None return self.adapter.__class__.__name__ def status(self): return self.adapter.status() def update(self): return self.adapter.update()
class TestGit(unittest.TestCase): """Git adapter test suite.""" sandbox = None git = None def setUp(self): """Set up git adapter and sandbox.""" self.sandbox = Sandbox() self.sandbox.mkdir("repo") self.git = Git(os.path.join(self.sandbox.path, "repo")) self.git.execute = Mock(return_value=None) def tearDown(self): """Unset test object.""" self.sandbox.destroy() self.git = None def test_status(self): """Test git status.""" self.git.status() self.git.execute.assert_called_once_with( "git status", os.path.join(self.sandbox.path, "repo")) def test_update(self): """Test git update.""" self.git.update() self.git.execute.assert_called_once_with( "git pull --rebase", os.path.join(self.sandbox.path, "repo")) def test_clone(self): """Test git status.""" self.git.clone("[email protected]:foo/bar") self.git.execute.assert_called_once_with( "git clone %s %s" % ( "[email protected]:foo/bar", os.path.join(self.sandbox.path, "repo")))