def test_source_tree_object(): """Verify that we throw an exception if not all required data is present.""" source = source_tree.SourceTree(proto_source.SourceRepository()) with pytest.raises(source_tree.SourceTreeError) as pull_exception: source.get_head_hash() assert "No origin is defined or can be" in str(pull_exception.value)
def _generate_source_tree_from_path(path: str) -> source_tree.SourceTree: """Build a source tree from a remote url.""" source_repository = proto_source.SourceRepository( identity=proto_source.SourceRepository.SourceIdentity.SRCID_ENVOY, source_path=path, ) return source_tree.SourceTree(source_repository)
def test_get_identity(): """Verify we can retrieve the identity out of a source repository object.""" for source_id in [ proto_source.SourceRepository.SourceIdentity.SRCID_UNSPECIFIED, proto_source.SourceRepository.SourceIdentity.SRCID_ENVOY, proto_source.SourceRepository.SourceIdentity.SRCID_NIGHTHAWK, ]: source_repository = proto_source.SourceRepository(identity=source_id) tree = source_tree.SourceTree(source_repository) identity = tree.get_identity() assert identity == source_id
def test_get_origin_fail(mock_get_source_directory, mock_run_command): """Verify that we raise an exception if we are unable to determine the source tree origin """ mock_get_source_directory.return_value = '/some_temp_directory' mock_run_command.return_value = 'definitely not any origin data we want' source_repository = proto_source.SourceRepository(source_path='/tmp') source = source_tree.SourceTree(source_repository) origin = '' with pytest.raises(source_tree.SourceTreeError) as source_error: origin = source.get_origin() assert not origin assert str(source_error.value) == \ "Unable to determine the origin url from /some_temp_directory"