Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_remove_version(self):
versions = Versions()
versions.add('1.0')
v = versions.remove('1.0')
self.assertEqual(v, VersionInfo('1.0'))
self.assertEqual(list(versions), [])
def test_dumps(self):
versions = Versions()
versions.add('2.0', '2.0.2', ['latest'])
versions.add('1.0', '1.0.1', ['stable'])
self.assertEqual(json.loads(versions.dumps()), [
{'version': '2.0', 'title': '2.0.2', 'aliases': ['latest']},
{'version': '1.0', 'title': '1.0.1', 'aliases': ['stable']}
])
def test_update_alias_aliases(self):
versions = Versions()
versions.add('1.0', '1.0.0', ['latest'])
diff = versions.update('latest', aliases=['greatest'])
self.assertEqual(diff, {'greatest'})
self.assertEqual(list(versions), [
VersionInfo('1.0', '1.0.0', ['latest', 'greatest']),
])
def test_remove_alias(self):
versions = Versions()
versions.add('1.0', aliases=['latest'])
v = versions.remove('latest')
self.assertEqual(v, 'latest')
self.assertEqual(list(versions), [
VersionInfo('1.0'),
])
def test_difference_update_nonexistent(self):
versions = Versions()
versions.add('1.0')
versions.add('2.0')
versions.add('3.0', aliases=['latest'])
with self.assertRaises(KeyError):
versions.difference_update(['1.0', 'latest', '4.0'])
self.assertEqual(list(versions), [
VersionInfo('3.0', aliases=['latest']),
VersionInfo('2.0'),
VersionInfo('1.0'),
])
def list_versions(branch='gh-pages'):
try:
return Versions.loads(git_utils.read_file(
branch, versions_file, universal_newlines=True
))
except git_utils.GitError:
return Versions()
def loads(data):
result = Versions()
for i in json.loads(data):
result.add(i['version'], i['title'], i['aliases'])
return result