def load_version(version_file: str = VERSION_FILE) -> NodeVersion: with open(version_file, 'r') as _f: version = json.load(_f) if not isinstance(version, collections.abc.Iterable): raise InvalidVersionError( "Failed to load from {}: data '{}' is not iterable".format( version_file, version)) return NodeVersion('.'.join([str(i) for i in version if str(i)]))
def set_version(version: str, version_file: str = VERSION_FILE): version = NodeVersion(version) with open(version_file, 'w') as _f: json.dump(['' if i is None else i for i in version.parts], _f) _f.write('\n')
def test_set_load_version_valid(version, version_file_path): set_version(version, version_file_path) assert load_version(version_file_path) == NodeVersion(version)
def test_node_version_upstream(): pv = NodeVersion('1.2.3') assert pv.upstream is pv
def test_node_version_parts(): assert NodeVersion('1.2.3.dev2').parts == (1, 2, 3, 'dev', 2) assert NodeVersion('1.2.3.rc3').parts == (1, 2, 3, 'rc', 3) assert NodeVersion('1.2.3').parts == (1, 2, 3, None, None)
def test_node_version_valid(version): NodeVersion(version)
def test_node_version_invalid_value(version): with pytest.raises(InvalidVersionError): NodeVersion(version)