Change Docker Version tests to pytest

This commit is contained in:
Joseph Schorr 2017-02-22 15:45:06 -05:00
parent 90f841175e
commit 94be8731f3
2 changed files with 40 additions and 46 deletions

View file

@ -1,14 +1,13 @@
import unittest import unittest
import magic
from _pyio import BufferedReader
from itertools import islice from itertools import islice
from semantic_version import Version, Spec
import magic
from util.validation import generate_valid_usernames, validate_username from util.validation import generate_valid_usernames, validate_username
from util.registry.generatorfile import GeneratorFile from util.registry.generatorfile import GeneratorFile
from util.registry.dockerver import docker_version
from util import slash_join from util import slash_join
from _pyio import BufferedReader
class TestUsernameValidation(unittest.TestCase): class TestUsernameValidation(unittest.TestCase):
def assertValid(self, username): def assertValid(self, username):
@ -200,48 +199,6 @@ class TestUsernameGenerator(unittest.TestCase):
self.assertEquals('a3', generated_output[3]) self.assertEquals('a3', generated_output[3])
class TestDockerVersionParsing(unittest.TestCase):
def test_parsing(self):
tests_cases = [
('docker/1.6.0 go/go1.4.2 git-commit/1234567 kernel/4.2.0-18-generic os/linux arch/amd64',
Version('1.6.0')),
('docker/1.7.1 go/go1.4.2 kernel/4.1.7-15.23.amzn1.x86_64 os/linux arch/amd64',
Version('1.7.1')),
('docker/1.6.2 go/go1.4.2 git-commit/7c8fca2-dirty kernel/4.0.5 os/linux arch/amd64',
Version('1.6.2')),
('docker/1.9.0 go/go1.4.2 git-commit/76d6bc9 kernel/3.16.0-4-amd64 os/linux arch/amd64',
Version('1.9.0')),
('docker/1.9.1 go/go1.4.2 git-commit/a34a1d5 kernel/3.10.0-229.20.1.el7.x86_64 os/linux arch/amd64',
Version('1.9.1')),
('docker/1.8.2-circleci go/go1.4.2 git-commit/a8b52f5 kernel/3.13.0-71-generic os/linux arch/amd64',
Version('1.8.2')),
('Go 1.1 package http', Version('1.5.0')),
('curl', None),
('docker/1.8 stuff', Version('1.8.0')),
]
for ua_string, ver_info in tests_cases:
parsed_ver = docker_version(ua_string)
self.assertEquals(ver_info, parsed_ver)
def test_specs(self):
test_cases = [
# (Spec, no_match_case_list, matching_case_list)
(Spec('<1.6.0'), ['1.6.0', '1.6.1', '1.9.0', '100.5.2'], ['0.0.0', '1.5.99']),
(Spec('<1.9.0'), ['1.9.0', '100.5.2'], ['0.0.0', '1.5.99', '1.6.0', '1.6.1']),
(Spec('<1.6.0,>0.0.1'), ['1.6.0', '1.6.1', '1.9.0', '0.0.0'], ['1.5.99']),
]
for spec, no_match_cases, match_cases in test_cases:
for no_match_case in no_match_cases:
self.assertFalse(spec.match(Version(no_match_case)),
'Spec: %s Case: %s' % (spec, no_match_case))
for match_case in match_cases:
self.assertTrue(spec.match(Version(match_case)),
'Spec: %s Case: %s' % (spec, match_case))
class TestSlashJoining(unittest.TestCase): class TestSlashJoining(unittest.TestCase):
def test_joining(self): def test_joining(self):
test_cases = [ test_cases = [

View file

@ -0,0 +1,37 @@
import pytest
from util.registry.dockerver import docker_version
from semantic_version import Version, Spec
@pytest.mark.parametrize('ua_string, ver_info', [
('docker/1.6.0 go/go1.4.2 git-commit/1234567 kernel/4.2.0-18-generic os/linux arch/amd64',
Version('1.6.0')),
('docker/1.7.1 go/go1.4.2 kernel/4.1.7-15.23.amzn1.x86_64 os/linux arch/amd64',
Version('1.7.1')),
('docker/1.6.2 go/go1.4.2 git-commit/7c8fca2-dirty kernel/4.0.5 os/linux arch/amd64',
Version('1.6.2')),
('docker/1.9.0 go/go1.4.2 git-commit/76d6bc9 kernel/3.16.0-4-amd64 os/linux arch/amd64',
Version('1.9.0')),
('docker/1.9.1 go/go1.4.2 git-commit/a34a1d5 kernel/3.10.0-229.20.1.el7.x86_64 os/linux arch/amd64',
Version('1.9.1')),
('docker/1.8.2-circleci go/go1.4.2 git-commit/a8b52f5 kernel/3.13.0-71-generic os/linux arch/amd64',
Version('1.8.2')),
('Go 1.1 package http', Version('1.5.0')),
('curl', None),
('docker/1.8 stuff', Version('1.8.0')),
])
def test_parsing(ua_string, ver_info):
parsed_ver = docker_version(ua_string)
assert parsed_ver == ver_info
@pytest.mark.parametrize('spec, no_match_cases, match_cases', [
(Spec('<1.6.0'), ['1.6.0', '1.6.1', '1.9.0', '100.5.2'], ['0.0.0', '1.5.99']),
(Spec('<1.9.0'), ['1.9.0', '100.5.2'], ['0.0.0', '1.5.99', '1.6.0', '1.6.1']),
(Spec('<1.6.0,>0.0.1'), ['1.6.0', '1.6.1', '1.9.0', '0.0.0'], ['1.5.99']),
])
def test_specs(spec, no_match_cases, match_cases):
for no_match_case in no_match_cases:
assert not spec.match(Version(no_match_case))
for match_case in match_cases:
assert spec.match(Version(match_case))