def test_guessed_summary_and_description_in_grand_parent_branch(self): """Testing BazaarClient guessing summary and description for grand parent branch""" self._bzr_add_file_commit('foo.txt', FOO1, 'commit 1', cwd=self.child_branch) self._bzr_add_file_commit('foo.txt', FOO2, 'commit 2', cwd=self.child_branch) self._bzr_add_file_commit('foo.txt', FOO3, 'commit 3', cwd=self.child_branch) self.options.guess_summary = True self.options.guess_description = True grand_child_branch = make_tempdir() self._run_bzr(['branch', '--use-existing-dir', self.child_branch, grand_child_branch], cwd=self.child_branch) os.chdir(grand_child_branch) # Requesting the diff between the grand child branch and its grand # parent: self.options.parent_branch = self.original_branch revisions = self.client.parse_revision_spec([]) commit_message = self.client.get_commit_message(revisions) self.assertEqual('commit 3', commit_message['summary']) description = commit_message['description'] self.assertTrue('commit 1' in description) self.assertTrue('commit 2' in description) self.assertFalse('commit 3' in description)
def test_parse_revision_spec_one_arg_parent(self): """Testing BazaarClient.parse_revision_spec with one specified revision and a parent diff""" os.chdir(self.original_branch) parent_base_commit_id = self.client._get_revno() grand_child_branch = make_tempdir() self._run_bzr(['branch', '--use-existing-dir', self.child_branch, grand_child_branch]) os.chdir(grand_child_branch) base_commit_id = self.client._get_revno() self._bzr_add_file_commit('foo.txt', FOO2, 'commit 2') tip_commit_id = self.client._get_revno() self.options.parent_branch = self.child_branch revisions = self.client.parse_revision_spec([tip_commit_id]) self.assertTrue(isinstance(revisions, dict)) self.assertTrue('parent_base' in revisions) self.assertTrue('base' in revisions) self.assertTrue('tip' in revisions) self.assertEqual(revisions['parent_base'], parent_base_commit_id) self.assertEqual(revisions['base'], base_commit_id) self.assertEqual(revisions['tip'], tip_commit_id)
def test_parse_revision_spec_one_arg_parent(self): """Testing BazaarClient.parse_revision_spec with one specified revision and a parent diff""" os.chdir(self.original_branch) parent_base_commit_id = self.client._get_revno() grand_child_branch = make_tempdir() self._run_bzr([ 'branch', '--use-existing-dir', self.child_branch, grand_child_branch ]) os.chdir(grand_child_branch) base_commit_id = self.client._get_revno() self._bzr_add_file_commit('foo.txt', FOO2, 'commit 2') tip_commit_id = self.client._get_revno() self.options.parent_branch = self.child_branch revisions = self.client.parse_revision_spec([tip_commit_id]) self.assertTrue(isinstance(revisions, dict)) self.assertTrue('parent_base' in revisions) self.assertTrue('base' in revisions) self.assertTrue('tip' in revisions) self.assertEqual(revisions['parent_base'], parent_base_commit_id) self.assertEqual(revisions['base'], base_commit_id) self.assertEqual(revisions['tip'], tip_commit_id)
def test_diff_grand_parent(self): """Testing BazaarClient diff with changes between a 2nd level descendant""" self._bzr_add_file_commit('foo.txt', FOO1, 'delete and modify stuff', cwd=self.child_branch) grand_child_branch = make_tempdir() self._run_bzr([ 'branch', '--use-existing-dir', self.child_branch, grand_child_branch ], cwd=self.child_branch) os.chdir(grand_child_branch) # Requesting the diff between the grand child branch and its grand # parent: self.options.parent_branch = self.original_branch revisions = self.client.parse_revision_spec([]) result = self.client.diff(revisions) self.assertTrue(isinstance(result, dict)) self.assertTrue('diff' in result) self._compare_diffs('foo.txt', result['diff'], 'a6326b53933f8b255a4b840485d8e210')
def setUp(self): super(TestCase, self).setUp() self._old_cwd = os.getcwd() self.old_home = self.get_user_home() if self.needs_temp_home: self.set_user_home(make_tempdir()) os.environ[str('RBTOOLS_EDITOR')] = str(self.default_text_editor)
def setUp(self): if not is_exe_in_path('bzr'): raise SkipTest('bzr not found in path') super(BazaarClientTests, self).setUp() self.set_user_home( os.path.join(self.testdata_dir, 'homedir')) self.original_branch = make_tempdir() self._run_bzr(['init', '.'], cwd=self.original_branch) self._bzr_add_file_commit('foo.txt', FOO, 'initial commit', cwd=self.original_branch) self.child_branch = make_tempdir() self._run_bzr(['branch', '--use-existing-dir', self.original_branch, self.child_branch], cwd=self.original_branch) self.client = BazaarClient(options=self.options) self.options.parent_branch = None
def test_make_empty_files(self): """Testing make_empty_files""" # Use make_tempdir to get a unique directory name tmpdir = make_tempdir() self.assertTrue(os.path.isdir(tmpdir)) cleanup_tempfiles() fname = os.path.join(tmpdir, 'file') make_empty_files([fname]) self.assertTrue(os.path.isdir(tmpdir)) self.assertTrue(os.path.isfile(fname)) self.assertEqual(os.stat(fname).st_uid, os.geteuid()) self.assertTrue(os.access(fname, os.R_OK | os.W_OK)) shutil.rmtree(tmpdir, ignore_errors=True)
def test_make_empty_files(self): """Testing 'make_empty_files' method.""" # Use make_tempdir to get a unique directory name tmpdir = filesystem.make_tempdir() self.assertTrue(os.path.isdir(tmpdir)) filesystem.cleanup_tempfiles() fname = os.path.join(tmpdir, 'file') filesystem.make_empty_files([fname]) self.assertTrue(os.path.isdir(tmpdir)) self.assertTrue(os.path.isfile(fname)) self.assertEqual(os.stat(fname).st_uid, os.geteuid()) self.assertTrue(os.access(fname, os.R_OK | os.W_OK)) shutil.rmtree(tmpdir, ignore_errors=True)
def setUp(self): if not is_exe_in_path('bzr'): raise SkipTest('bzr not found in path') super(BazaarClientTests, self).setUp() self.set_user_home(os.path.join(self.testdata_dir, 'homedir')) self.original_branch = make_tempdir() self._run_bzr(['init', '.'], cwd=self.original_branch) self._bzr_add_file_commit('foo.txt', FOO, 'initial commit', cwd=self.original_branch) self.child_branch = make_tempdir() self._run_bzr([ 'branch', '--use-existing-dir', self.original_branch, self.child_branch ], cwd=self.original_branch) self.client = BazaarClient(options=self.options) self.options.parent_branch = None
def chdir_tmp(self): """Create a temporary directory and set it as the working directory. The directory will be deleted after the test has finished. Version Added: 3.0 Returns: unicode: The path to the temp directory. """ dirname = make_tempdir() os.chdir(dirname) return dirname
def test_diff_parent(self): """Testing BazaarClient diff with changes only in the parent branch""" self._bzr_add_file_commit('foo.txt', FOO1, 'delete and modify stuff', cwd=self.child_branch) grand_child_branch = make_tempdir() self._run_bzr(['branch', '--use-existing-dir', self.child_branch, grand_child_branch], cwd=self.child_branch) os.chdir(grand_child_branch) revisions = self.client.parse_revision_spec([]) result = self.client.diff(revisions) self.assertTrue(isinstance(result, dict)) self.assertTrue('diff' in result) self.assertEqual(result['diff'], None)
def setUpClass(cls): super(SCMClientTestCase, cls).setUpClass() cls.testdata_dir = os.path.join(os.path.dirname(__file__), 'testdata') # We'll set up a common suite-wide temp directory for storing both the # cached copy of the checkout(s) needed by the suite, and a working # area copy (which unit tests can modify). # # To ensure paths are always correct, checkouts will be placed in the # working directory, and then moved to the "main" directory. cls._checkout_base_dir = make_tempdir(track=False) cls._checkout_cache_dir = os.path.join(cls._checkout_base_dir, 'cache') cls._checkout_working_dir = os.path.join(cls._checkout_base_dir, 'working') cls.checkout_dir = cls.setup_checkout(cls._checkout_working_dir) if cls.checkout_dir: shutil.move(cls._checkout_working_dir, cls._checkout_cache_dir)
def test_diff_parent(self): """Testing BazaarClient diff with changes only in the parent branch""" self._bzr_add_file_commit('foo.txt', FOO1, 'delete and modify stuff', cwd=self.child_branch) grand_child_branch = make_tempdir() self._run_bzr([ 'branch', '--use-existing-dir', self.child_branch, grand_child_branch ], cwd=self.child_branch) os.chdir(grand_child_branch) revisions = self.client.parse_revision_spec([]) result = self.client.diff(revisions) self.assertTrue(isinstance(result, dict)) self.assertTrue('diff' in result) self.assertEqual(result['diff'], None)
def test_guessed_summary_and_description_in_grand_parent_branch(self): """Testing BazaarClient guessing summary and description for grand parent branch""" self._bzr_add_file_commit('foo.txt', FOO1, 'commit 1', cwd=self.child_branch) self._bzr_add_file_commit('foo.txt', FOO2, 'commit 2', cwd=self.child_branch) self._bzr_add_file_commit('foo.txt', FOO3, 'commit 3', cwd=self.child_branch) self.options.guess_summary = True self.options.guess_description = True grand_child_branch = make_tempdir() self._run_bzr([ 'branch', '--use-existing-dir', self.child_branch, grand_child_branch ], cwd=self.child_branch) os.chdir(grand_child_branch) # Requesting the diff between the grand child branch and its grand # parent: self.options.parent_branch = self.original_branch revisions = self.client.parse_revision_spec([]) commit_message = self.client.get_commit_message(revisions) self.assertEqual('commit 3', commit_message['summary']) description = commit_message['description'] self.assertTrue('commit 1' in description) self.assertTrue('commit 2' in description) self.assertFalse('commit 3' in description)
def setUp(self): super(MercurialSubversionClientTests, self).setUp() self._hg_env = {'FOO': 'BAR'} # Make sure hgsubversion is enabled. # # This will modify the .hgrc in the temp home directory created # for these tests. # # The "hgsubversion =" tells Mercurial to check for hgsubversion # in the default PYTHONPATH. fp = open('%s/.hgrc' % os.environ['HOME'], 'w') fp.write('[extensions]\n') fp.write('hgsubversion =\n') fp.close() for exe in self._required_exes: if not is_exe_in_path(exe): raise SkipTest('missing svn stuff! giving up!') if not self._has_hgsubversion(): raise SkipTest('unable to use `hgsubversion` extension! ' 'giving up!') if not self._tmpbase: self._tmpbase = make_tempdir() self._create_svn_repo() self._fire_up_svnserve() self._fill_in_svn_repo() try: self._get_testing_clone() except (OSError, IOError): msg = 'could not clone from svn repo! skipping...' raise SkipTest(msg).with_traceback(sys.exc_info()[2]) self._spin_up_client() self._stub_in_config_and_options()
def test_diff_grand_parent(self): """Testing BazaarClient diff with changes between a 2nd level descendant""" self._bzr_add_file_commit('foo.txt', FOO1, 'delete and modify stuff', cwd=self.child_branch) grand_child_branch = make_tempdir() self._run_bzr(['branch', '--use-existing-dir', self.child_branch, grand_child_branch], cwd=self.child_branch) os.chdir(grand_child_branch) # Requesting the diff between the grand child branch and its grand # parent: self.options.parent_branch = self.original_branch revisions = self.client.parse_revision_spec([]) result = self.client.diff(revisions) self.assertTrue(isinstance(result, dict)) self.assertTrue('diff' in result) self._compare_diffs('foo.txt', result['diff'], 'a6326b53933f8b255a4b840485d8e210')
def chdir_tmp(self, dir=None): """Changes current directory to a temporary directory.""" dirname = make_tempdir(parent=dir) os.chdir(dirname) return dirname
def create_tmp_dir(self): """Creates and returns a temporary directory.""" return make_tempdir()
def set_user_home_tmp(self): """Set temporary directory as current user's home.""" self.set_user_home(make_tempdir())