def test_get_git_url_ssh_enterprise(self) -> None:
     true_url = 'https://github.tap.com/test_account/test_repo'
     subprocess.run([
         'git', 'remote', 'set-url', 'origin',
         '[email protected]:test_account/test_repo.git'
     ])
     self.assertEqual(get_git_url(commit_hash=False), true_url)
Example #2
0
    def get_reproducibility_info() -> Dict[str, str]:
        """Gets a dictionary of reproducibility information.

        Reproducibility information always includes:
        - command_line: The command line command used to execute the code.
        - time: The current time.

        If git is installed, reproducibility information also includes:
        - git_root: The root of the git repo where the command is run.
        - git_url: The url of the current hash of the git repo where the command is run.
                   Ex. https://github.com/swansonk14/rationale-alignment/tree/<hash>
        - git_has_uncommitted_changes: Whether the current git repo has uncommitted changes.

        :return: A dictionary of reproducibility information.
        """
        reproducibility = {
            'command_line': f'python {" ".join(sys.argv)}',
            'time': time.strftime('%c')
        }

        if has_git():
            reproducibility['git_root'] = get_git_root()
            reproducibility['git_url'] = get_git_url(commit_hash=True)
            reproducibility[
                'git_has_uncommitted_changes'] = has_uncommitted_changes()

        return reproducibility
 def test_get_git_url_ssh_hash(self) -> None:
     subprocess.run([
         'git', 'remote', 'set-url', 'origin',
         '[email protected]:test_account/test_repo.git'
     ])
     url = f'{self.url}/tree/'
     self.assertEqual(get_git_url(commit_hash=True)[:len(url)], url)
 def test_get_git_url_ssh_hash_enterprise(self) -> None:
     true_url = 'https://github.tap.com/test_account/test_repo'
     subprocess.run([
         'git', 'remote', 'set-url', 'origin',
         '[email protected]:test_account/test_repo.git'
     ])
     url = f'{true_url}/tree/'
     self.assertEqual(get_git_url(commit_hash=True)[:len(url)], url)
 def test_get_git_url_ssh(self) -> None:
     subprocess.run([
         'git', 'remote', 'set-url', 'origin',
         '[email protected]:test_account/test_repo.git'
     ])
     self.assertEqual(get_git_url(commit_hash=False), self.url)
 def test_get_git_url_https_hash(self) -> None:
     url = f'{self.url}/tree/'
     self.assertEqual(get_git_url(commit_hash=True)[:len(url)], url)
 def test_get_git_url_https(self) -> None:
     self.assertEqual(get_git_url(commit_hash=False), self.url)