diff options
-rw-r--r-- | doc/reference.rst | 12 | ||||
-rw-r--r-- | src/semantic_version/base.py | 5 | ||||
-rwxr-xr-x | tests/test_base.py | 16 |
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'], |