def find(self, part='patch'): """ Attempt to find Version according to the pattern from version config file. :return: Version object, Version object with nulled patch or None, None if not found """ with io.open(self.path, 'rb') as f: for line in f.readlines(): match = self._versionconfig.parse_regex.search( line.decode('utf-8').rstrip("\n")) if match: _parsed = {} _parsed_zero_patch = {} for key, value in match.groupdict().items(): if key == part: _parsed_zero_patch[key] = VersionPart( '0', self._versionconfig.part_configs.get(key)) else: _parsed_zero_patch[key] = VersionPart( value, self._versionconfig.part_configs.get(key)) _parsed[key] = VersionPart( value, self._versionconfig.part_configs.get(key)) return Version(_parsed, str(_parsed)), Version( _parsed_zero_patch, str(_parsed_zero_patch)) return None, None
def parse(self, version_string): regexp_one_line = "".join([ l.split("#")[0].strip() for l in self.parse_regex.pattern.splitlines() ]) logger.info("Parsing version '{}' using regexp '{}'".format( version_string, regexp_one_line)) match = self.parse_regex.search(version_string) _parsed = {} if not match: logger.warn( "Evaluating 'parse' option: '{}' does not parse current version '{}'" .format(self.parse_regex.pattern, version_string)) return for key, value in match.groupdict().items(): _parsed[key] = VersionPart(value, self.part_configs.get(key)) v = Version(_parsed, version_string) logger.info("Parsed the following values: %s" % keyvaluestring(v._values)) return v
def test_version_part_null(confvpc): assert VersionPart(confvpc.first_value, confvpc).null() == VersionPart( confvpc.first_value, confvpc)
def test_version_part_equality(confvpc): assert VersionPart(confvpc.first_value, confvpc) == VersionPart( confvpc.first_value, confvpc)
def test_version_part_format(confvpc): assert "{}".format( VersionPart(confvpc.first_value, confvpc)) == confvpc.first_value
def test_version_part_check_optional_true(confvpc): assert VersionPart(confvpc.first_value, confvpc).is_optional()
def test_version_part_check_optional_false(confvpc): assert not VersionPart(confvpc.first_value, confvpc).bump().is_optional()
def test_version_part_bump(confvpc): vp = VersionPart(confvpc.first_value, confvpc) vc = vp.bump() assert vc.value == confvpc.bump(confvpc.first_value)
def test_version_part_copy(confvpc): vp = VersionPart(confvpc.first_value, confvpc) vc = vp.copy() assert vp.value == vc.value assert id(vp) != id(vc)
def test_version_part_init(confvpc): assert VersionPart( confvpc.first_value, confvpc).value == confvpc.first_value