Permalink
Browse files

Add blah.is_source_control_uri

  • Loading branch information...
1 parent 2819214 commit ce15a6d93016da78c8ccf014a2935ee1490182cd @mwilliamson committed Dec 9, 2012
Showing with 40 additions and 4 deletions.
  1. +8 −1 blah/__init__.py
  2. +8 −0 blah/systems.py
  3. +2 −2 setup.py
  4. +0 −1 tests/fetcher_tests.py
  5. +22 −0 tests/systems_tests.py
View
@@ -1,5 +1,12 @@
from blah.fetcher import fetch
from blah.repositories import find_repository, repository_at
from blah.errors import UnrecognisedSourceControlSystem
+from blah.systems import is_source_control_uri
-__all__ = ["fetch", "find_repository", "repository_at", "UnrecognisedSourceControlSystem"]
+__all__ = [
+ "fetch",
+ "find_repository",
+ "repository_at",
+ "is_source_control_uri",
+ "UnrecognisedSourceControlSystem"
+]
View
@@ -1,7 +1,15 @@
from blah.git import Git
from blah.hg import Hg
+import blah.uri_parser
all_systems = [
Git(),
Hg()
]
+
+def is_source_control_uri(uri):
+ parsed_uri = blah.uri_parser.parse(uri)
+ return parsed_uri.vcs is not None and _is_recognised_prefix(parsed_uri.vcs)
+
+def _is_recognised_prefix(prefix):
+ return any(prefix == vcs.name for vcs in all_systems)
View
@@ -8,12 +8,12 @@ def read(fname):
setup(
name='blah',
- version='0.1.6',
+ version='0.1.7',
description='Thin wrapper around source control systems',
long_description=read("README"),
author='Michael Williamson',
url='http://github.com/mwilliamson/blah',
scripts=["scripts/blah"],
packages=['blah'],
- install_requires=["argparse==1.2.1"],
+ install_requires=["argparse==1.2.1", "nose==1.2.1"],
)
View
@@ -2,7 +2,6 @@
import functools
from nose.tools import istest, assert_equal
-import mock
from blah.fetcher import fetch
from blah.files import mkdir_p, temporary_directory, write_file, read_file
View
@@ -0,0 +1,22 @@
+from nose.tools import istest, assert_true, assert_false
+
+import blah.systems
+
+@istest
+def uri_is_recognised_if_it_has_known_source_control_prefix():
+ _assert_is_source_control_uri("git+file:///tmp/blah")
+ _assert_is_source_control_uri("git+https://github.com/mwilliamson/blah.git")
+
+@istest
+def uri_is_not_recognised_if_it_has_no_prefix():
+ _assert_is_not_source_control_uri("file:///tmp/blah")
+
+@istest
+def uri_is_not_recognised_if_prefix_is_not_known():
+ _assert_is_not_source_control_uri("local+file:///tmp/blah")
+
+def _assert_is_source_control_uri(uri):
+ assert_true(blah.systems.is_source_control_uri(uri))
+
+def _assert_is_not_source_control_uri(uri):
+ assert_false(blah.systems.is_source_control_uri(uri))

0 comments on commit ce15a6d

Please sign in to comment.