def setUp(self) -> None: self.host = bitbucket.BitbucketHost( typedefs.GitConfig('', 'master'), 'albertyw', 'git-browse', ) self.repository_url = 'https://bitbucket.org/albertyw/git-browse' self.focus_object = typedefs.FocusObject('/') self.focus_hash = typedefs.FocusHash(test_util.get_tag())
def setUp(self) -> None: self.github_host = github.GithubHost( typedefs.GitConfig('', 'master'), 'albertyw', 'git-browse', ) self.repository_url = 'https://github.com/albertyw/git-browse' self.focus_object = typedefs.FocusObject('/') self.focus_hash = typedefs.FocusHash(test_util.get_tag())
def get_git_object(focus_object: str, path: pathlib.Path, host: typedefs.Host) -> typedefs.GitObject: if not focus_object: return typedefs.FocusObject.default() object_path = path.joinpath(focus_object).resolve() if not object_path.exists(): focus_hash = get_commit_hash(focus_object) if focus_hash: return focus_hash error = "specified file does not exist: %s" % object_path raise FileNotFoundError(error) object_path_str = str(object_path.relative_to(get_repository_root())) if object_path.is_dir() and object_path_str[-1] != os.sep: object_path_str += os.sep return typedefs.FocusObject(object_path_str)
def setUp(self) -> None: self.phabricator_host = phabricator.PhabricatorHost() self.phabricator_url = 'https://example.com' self.repository_callsign = 'ASDF' self.default_branch = 'master' self.phabricator_host.phabricator_url = self.phabricator_url self.phabricator_host.repository_callsign = self.repository_callsign self.phabricator_host.default_branch = self.default_branch self.focus_object = typedefs.FocusObject('/') self.focus_hash = typedefs.FocusHash(test_util.get_tag()) self.arcconfig_data = { 'phabricator.uri': self.phabricator_url, 'repository.callsign': self.repository_callsign, 'git.default-relative-commit': 'origin/master', } self.temp_dir = tempfile.TemporaryDirectory() self.temp_dir_name = pathlib.Path(self.temp_dir.name) self.arcconfig_file = self.temp_dir_name / '.arcconfig' with open(self.arcconfig_file, 'w') as handle: handle.write(json.dumps(self.arcconfig_data))
def test_get_url_file(self) -> None: git_object = typedefs.FocusObject('zxcv') url = self.obj.get_url(git_object) self.assertEqual( url, sourcegraph.UBER_SOURCEGRAPH_URL + 'code.uber.internal/asdf/-/blob/zxcv')
def test_get_url_directory(self) -> None: git_object = typedefs.FocusObject('zxcv' + os.sep) url = self.obj.get_url(git_object) self.assertEqual( url, sourcegraph.UBER_SOURCEGRAPH_URL + 'code.uber.internal/asdf/-/tree/zxcv/')
def test_get_url_root(self) -> None: git_object = typedefs.FocusObject(os.sep) url = self.obj.get_url(git_object) self.assertEqual( url, sourcegraph.UBER_SOURCEGRAPH_URL + 'code.uber.internal/asdf')
def test_get_url_file(self) -> None: git_object = typedefs.FocusObject('zxcv') with self.assertRaises(NotImplementedError): self.obj.get_url(git_object)
def test_get_url_directory(self) -> None: git_object = typedefs.FocusObject('zxcv' + os.sep) url = self.obj.get_url(git_object) self.assertEqual( url, godocs.PUBLIC_GODOCS_URL + 'github.com/asdf/qwer/zxcv/')
def test_get_url_root(self) -> None: git_object = typedefs.FocusObject(os.sep) url = self.obj.get_url(git_object) self.assertEqual(url, godocs.PUBLIC_GODOCS_URL + 'github.com/asdf/qwer')
def test_is_not_directory(self) -> None: obj = typedefs.FocusObject('/asdf') self.assertFalse(obj.is_directory())
def test_is_directory(self) -> None: obj = typedefs.FocusObject('/asdf/') self.assertTrue(obj.is_directory())
def test_is_not_root(self) -> None: obj = typedefs.FocusObject('/asdf/') self.assertFalse(obj.is_root())
def test_is_root(self) -> None: obj = typedefs.FocusObject('/') self.assertTrue(obj.is_root())
def test_init(self) -> None: obj = typedefs.FocusObject('/asdf') self.assertEqual(obj.identifier, '/asdf')