コード例 #1
0
 def test_bundle_all(self):
     """Tests bundling multiple real repositories. This uses an array of URLs that 
        represent smallish repositories that are unlikely to go away."""
     print("\ntest_bundle_all")
     repo_urls = [
         "https://github.com/octocat/Hello-World.git",
         "https://github.com/octocat/git-consortium",
         "https://bitbucket.org/atlassian_tutorial/helloworld.git",
         "https://github.com/Microsoft/api-guidelines",
     ]
     throttler = bundle_repos.Throttler(2.0)
     config = bundle_repos.BundleConfig()
     config.throttler = throttler
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, 'repositories')
         os.mkdir(bundles_dir)
         print("bundles dir: {}".format(bundles_dir))
         num_ok = bundle_repos.Bundler(bundles_dir, tmpdir,
                                       config=config).bundle_all(repo_urls)
         self.assertEqual(num_ok, len(repo_urls))
         bundle_files = tests.list_files_recursively(bundles_dir)
         print("bundle files: {}".format(bundle_files))
         self.assertEqual(len(bundle_files), len(repo_urls))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'github.com', 'octocat',
                           'Hello-World.git.bundle')))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'github.com', 'octocat',
                           'git-consortium.bundle')))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'github.com', 'Microsoft',
                           'api-guidelines.bundle')))
         self.assertBundleVerifies(
             (os.path.join(bundles_dir, 'bitbucket.org',
                           'atlassian_tutorial', 'helloworld.git.bundle')))
コード例 #2
0
 def test_bundle_required(self):
     source_bundle_path = tests.get_data_dir('sample-repo-branched.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     original_hash = tests.hash_file(original_bundle_path)
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         old_metadata = os.stat(dest_bundle_path)
         bundler = bundle_repos.Bundler(tmpdir, tmpdir)
         old_latest_commit = bundle_repos.read_git_latest_commit_from_bundle(
             dest_bundle_path, tmpdir, bundler.git_runner)
         assert old_latest_commit == KNOWN_SAMPLE_REPO_LATEST_COMMIT_HASH
         new_bundle_path = bundler.bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_latest_commit = bundle_repos.read_git_latest_commit_from_bundle(
             new_bundle_path, tmpdir, bundler.git_runner)
         self.assertEqual(
             new_latest_commit,
             KNOWN_SAMPLE_REPO_BRANCHED_LATEST_COMMIT_HASH,
             "latest commit hash from sample-repo-branched is incorrect")
         new_hash = tests.hash_file(new_bundle_path)
         new_metadata = os.stat(new_bundle_path)
         self.assertNotEqual(new_metadata, old_metadata,
                             "metadata should have changed")
         self.assertNotEqual(new_hash, original_hash,
                             "hash should have changed")
コード例 #3
0
 def make_bundler(self, tempdir, config=None):
     assert (config is None) or isinstance(config,
                                           bundle_repos.BundleConfig)
     return bundle_repos.Bundler(tempdir,
                                 tempdir,
                                 git=self.git_script,
                                 config=config)
コード例 #4
0
 def test_bundle_one(self):
     print("\ntest_bundle_one")
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, 'repositories')
         os.mkdir(bundles_dir)
         bundle_path = bundle_repos.Bundler(bundles_dir, tmpdir).bundle(
             Repository("https://github.com/octocat/Hello-World.git"))
         self.assertIsNotNone(bundle_path, "bundle returned None")
         self.assertBundleVerifies(bundle_path)
コード例 #5
0
 def test_bundle_from_bundle_source(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     assert os.path.isfile(source_bundle_path)
     repo = Repository(pathlib.Path(source_bundle_path).as_uri())
     with tests.TemporaryDirectory() as tmpdir:
         bundler = bundle_repos.Bundler(tmpdir, tmpdir)
         bundle_path = bundler.bundle(repo)
         # not sure of an independent way to check that this bundle is correct
         self.assertIsNotNone(bundle_path, "bundle path is None")
         self.assertBundleVerifies(bundle_path)
コード例 #6
0
 def test_bundle_fail(self):
     """Tests bundling a repository that does not exist, causing a failure"""
     print("\ntest_bundle_fail")
     repo_urls = ["file:///path/to/nowhere.bundle"]
     with tests.TemporaryDirectory() as tmpdir:
         bundles_dir = os.path.join(tmpdir, "repositories")
         os.mkdir(bundles_dir)
         num_ok = bundle_repos.Bundler(bundles_dir,
                                       tmpdir).bundle_all(repo_urls)
         self.assertEqual(0, num_ok, "num_ok")
         for url in repo_urls:
             potential_bundle_path = Repository(url).make_bundle_path(
                 bundles_dir)
             self.assertFalse(
                 os.path.exists(potential_bundle_path),
                 "file exists at {} but shouldn't".format(
                     potential_bundle_path))
コード例 #7
0
 def test_bundle_not_required_force(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         original_metadata = os.stat(dest_bundle_path)
         config = bundle_repos.BundleConfig(ignore_rev=True)
         new_bundle_path = bundle_repos.Bundler(tmpdir,
                                                tmpdir,
                                                config=config).bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_metadata = os.stat(new_bundle_path)
         self.assertNotEqual(new_metadata, original_metadata,
                             "file metadata should have changed")
コード例 #8
0
 def test_bundle_not_required_skip(self):
     source_bundle_path = tests.get_data_dir('sample-repo.bundle')
     source_bundle_uri = pathlib.PurePath(source_bundle_path).as_uri()
     original_bundle_path = tests.get_data_dir('sample-repo.bundle')
     original_hash = tests.hash_file(original_bundle_path)
     with tests.TemporaryDirectory() as tmpdir:
         repo = Repository(source_bundle_uri)
         dest_bundle_path = repo.make_bundle_path(tmpdir)
         os.makedirs(os.path.dirname(dest_bundle_path))
         shutil.copyfile(original_bundle_path, dest_bundle_path)
         original_metadata = os.stat(dest_bundle_path)
         new_bundle_path = bundle_repos.Bundler(tmpdir, tmpdir).bundle(repo)
         self.assertEqual(new_bundle_path, dest_bundle_path)
         new_hash = tests.hash_file(new_bundle_path)
         self.assertEqual(new_hash, original_hash,
                          "hash should NOT have changed")
         new_metadata = os.stat(new_bundle_path)
         self.assertEqual(new_metadata, original_metadata,
                          "file metadata should NOT have changed")