summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-05-18 01:31:36 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-05-18 01:31:36 +0200
commit3e4f3936e187cdc9625bc30d9d2b27ecd91d8e59 (patch)
tree8ebef768460fd6fc8b105d9d3c754a81f5ac301d
parentae57afda5cc99616d8a6f388cffbf0ec23f59c6a (diff)
downloadsemantic-version-3e4f3936e187cdc9625bc30d9d2b27ecd91d8e59.tar.gz
Allow passing in spec lists in separate arguments to SpecList.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
-rw-r--r--doc/reference.rst12
-rw-r--r--src/semantic_version/base.py5
-rwxr-xr-xtests/test_base.py16
3 files changed, 30 insertions, 3 deletions
diff --git a/doc/reference.rst b/doc/reference.rst
index 310b4a8..9d2619f 100644
--- a/doc/reference.rst
+++ b/doc/reference.rst
@@ -370,7 +370,7 @@ It may be useful to define a rule such as
This is possible with the :class:`SpecList` class.
-.. class:: SpecList(spec_string)
+.. class:: SpecList(spec_string[, spec_string[, ...]])
Stores a list of :class:`Spec` and matches any :class:`Version` against all
contained :class:`specs <Spec>`.
@@ -384,6 +384,16 @@ This is possible with the :class:`SpecList` class.
<Spec: !~ <~SemVer: 1 1 4 None None>>
)>
+ Version specifications may also be passed in separated arguments::
+
+ >>> SpecList('>~1.0.0', '<1.2.0', '!~1.1.4,!~1.1.13')
+ <SpecList: (
+ <Spec: >~ <~SemVer: 1 0 0 None None>>,
+ <Spec: < <SemVer: 1 2 0 [] []>>,
+ <Spec: !~ <~SemVer: 1 1 4 None None>>
+ <Spec: !~ <~SemVer: 1 1 13 None None>>
+ )>
+
.. rubric:: Attributes
diff --git a/src/semantic_version/base.py b/src/semantic_version/base.py
index d776143..bec1a79 100644
--- a/src/semantic_version/base.py
+++ b/src/semantic_version/base.py
@@ -324,8 +324,9 @@ class Spec(object):
class SpecList(object):
- def __init__(self, specs_string):
- self.specs = self.parse(specs_string)
+ def __init__(self, *specs_strings):
+ subspecs = [self.parse(spec) for spec in specs_strings]
+ self.specs = sum(subspecs, ())
@classmethod
def parse(self, specs_string):
diff --git a/tests/test_base.py b/tests/test_base.py
index 6dbda18..894c4c3 100755
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -293,6 +293,22 @@ class SpecListTestCase(unittest.TestCase):
for spec_text in specs:
self.assertTrue(repr(base.Spec(spec_text)) in repr(spec_list))
+ split_examples = {
+ ('>=0.1.1', '<0.1.2', '!=0.1.1+build1'): ['>=0.1.1', '<0.1.2', '!=0.1.1+build1'],
+ ('>~0.1', '!=0.1.3-rc1,<0.1.3'): ['>~0.1', '!=0.1.3-rc1', '<0.1.3'],
+ }
+
+ def test_parsing_split(self):
+ for spec_list_texts, specs in self.split_examples.items():
+ spec_list = base.SpecList(*spec_list_texts)
+
+ self.assertEqual(','.join(spec_list_texts), str(spec_list))
+ self.assertEqual(specs, [str(spec) for spec in spec_list])
+ self.assertEqual(spec_list, base.SpecList(','.join(spec_list_texts)))
+
+ for spec_text in specs:
+ self.assertTrue(repr(base.Spec(spec_text)) in repr(spec_list))
+
matches = {
'>=0.1.1,<0.1.2': (
['0.1.1', '0.1.2-alpha', '0.1.1+4'],