From ed05a9ff622e6ddbff3406e05c4f611e77a5231f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 1 Aug 2013 16:15:45 +0000 Subject: Add GitDirectory class --- morphlib/gitdir_tests.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 morphlib/gitdir_tests.py (limited to 'morphlib/gitdir_tests.py') diff --git a/morphlib/gitdir_tests.py b/morphlib/gitdir_tests.py new file mode 100644 index 00000000..2494981a --- /dev/null +++ b/morphlib/gitdir_tests.py @@ -0,0 +1,66 @@ +# Copyright (C) 2013 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# =*= License: GPL-2 =*= + + +import os +import shutil +import tempfile +import unittest + +import morphlib + + +class GitDirectoryTests(unittest.TestCase): + + def setUp(self): + self.tempdir = tempfile.mkdtemp() + self.dirname = os.path.join(self.tempdir, 'foo') + + def tearDown(self): + shutil.rmtree(self.tempdir) + + def fake_git_clone(self): + os.mkdir(self.dirname) + os.mkdir(os.path.join(self.dirname, '.git')) + + def test_has_dirname_attribute(self): + self.fake_git_clone() + gitdir = morphlib.gitdir.GitDirectory(self.dirname) + self.assertEqual(gitdir.dirname, self.dirname) + + def test_runs_command_in_right_directory(self): + self.fake_git_clone() + gitdir = morphlib.gitdir.GitDirectory(self.dirname) + output = gitdir._runcmd(['pwd']) + self.assertEqual(output.strip(), self.dirname) + + def test_sets_and_gets_configuration(self): + os.mkdir(self.dirname) + gitdir = morphlib.gitdir.init(self.dirname) + gitdir.set_config('foo.bar', 'yoyo') + self.assertEqual(gitdir.get_config('foo.bar'), 'yoyo') + + def test_sets_remote(self): + os.mkdir(self.dirname) + gitdir = morphlib.gitdir.init(self.dirname) + self.assertEqual(gitdir.get_remote_fetch_url('origin'), None) + + gitdir._runcmd(['git', 'remote', 'add', 'origin', 'foobar']) + url = 'git://git.example.com/foo' + gitdir.set_remote_fetch_url('origin', url) + self.assertEqual(gitdir.get_remote_fetch_url('origin'), url) + -- cgit v1.2.1