def _norm_str(self, text, oldval=None): text = text.strip() if not text: self._raiseBadValu(text, mesg='No text left after stripping whitespace') subs = s_version.parseSemver(text) if subs is None: self._raiseBadValu(text, mesg='Unable to parse string as a semver.') valu = s_version.packVersion(subs.get('major'), subs.get('minor'), subs.get('patch')) return valu, subs
def _normPyStr(self, valu): valu = valu.strip() if not valu: raise s_exc.BadTypeValu(valu=valu, name=self.name, mesg='No text left after stripping whitespace') subs = s_version.parseSemver(valu) if subs is None: raise s_exc.BadTypeValu(valu=valu, name=self.name, mesg='Unable to parse string as a semver.') valu = s_version.packVersion(subs.get('major'), subs.get('minor'), subs.get('patch')) return valu, {'subs': subs}
def test_version_parseSemver(self): data = ( ('1.2.3', {'major': 1, 'minor': 2, 'patch': 3, }), ('0.0.1', {'major': 0, 'minor': 0, 'patch': 1, }), ('1.2.3-alpha', {'major': 1, 'minor': 2, 'patch': 3, 'pre': 'alpha', }), ('1.2.3-alpha.1', {'major': 1, 'minor': 2, 'patch': 3, 'pre': 'alpha.1', }), ('1.2.3-0.3.7', {'major': 1, 'minor': 2, 'patch': 3, 'pre': '0.3.7', }), ('1.2.3-x.7.z.92', {'major': 1, 'minor': 2, 'patch': 3, 'pre': 'x.7.z.92', }), ('1.2.3-alpha+001', {'major': 1, 'minor': 2, 'patch': 3, 'pre': 'alpha', 'build': '001'}), ('1.2.3+20130313144700', {'major': 1, 'minor': 2, 'patch': 3, 'build': '20130313144700'}), ('1.2.3-beta+exp.sha.5114f85', {'major': 1, 'minor': 2, 'patch': 3, 'pre': 'beta', 'build': 'exp.sha.5114f85'}), # Real world examples ('1.2.3-B5CD5743F', {'major': 1, 'minor': 2, 'patch': 3, 'pre': 'B5CD5743F', }), ('V1.2.3', {'major': 1, 'minor': 2, 'patch': 3, }), ('V1.4.0-RC0', {'major': 1, 'minor': 4, 'patch': 0, 'pre': 'RC0', }), ('v2.4.1-0.3.rc1', {'major': 2, 'minor': 4, 'patch': 1, 'pre': '0.3.rc1'}), ('0.18.1', {'major': 0, 'minor': 18, 'patch': 1, }), # Invalid semvers ('1', None), ('1.2', None), ('2.0A1', None), ('0.18rc2', None), ('0.0.00001', None), ('2016-03-01', None), ('v2.4.0.0-1', None), ('1.3a2.dev12', None), ('OpenSSL_1_0_2l', None), ('1.2.windows-RC1', None), ('v2.4.1.0-0.3.rc1', None), ) for s, e in data: r = s_version.parseSemver(s) self.eq(r, e)