From 8eb932577d177a4ec4fa365d4765072e8c025c15 Mon Sep 17 00:00:00 2001 From: wolfyeva Date: Wed, 18 May 2022 12:19:21 +0800 Subject: [PATCH] test: add parametrize tests --- tests/test_parse_file.py | 72 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index c66e336..6019897 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -1,10 +1,10 @@ +import pytest from compose_viz.parser import Parser from compose_viz.compose import Compose from compose_viz.service import Service - -def test_parse_file(): - expected: Compose = Compose([ +@pytest.mark.parametrize("test_input,expected",[ + ('tests/in/000001.yaml',Compose([ Service( name='frontend', image='awesome/webapp', @@ -20,10 +20,72 @@ def test_parse_file(): image='awesome/backend', networks=['back-tier', 'admin'], ), + ])), + ('tests/in/000010.yaml',Compose([ + Service( + name='base', + image='busybox', + user='root', + ), + Service( + name='common', + image='busybox', + extends='base' + ), + Service( + name='cli', + extends='common' + ), + ])), + ('tests/in/000100.yaml',Compose([ + #version='3.9' + Service( + build='.', + ports=['8000:5000'] + ), + Service( + name='redis', + image='redis:alpine', + ), + ])), + ('tests/in/001000.yaml',Compose([ + Service( + name='web', + build='.', + depends_on=['db','redis'] + ), + Service( + name='redis', + image='redis' + ), + Service( + name='db', + image='postgres' + ), + ])), + ('tests/in/010000.yaml',Compose([ + Service( + name='backend', + image='awesome/backend', + volumes=['db-data'] + ) + ])), + ('tests/in/100000.yaml',Compose([ + Service( + name='web', + build='.', + links=['db:database'] + ), + Service( + name='db', + image='postgres' + ) + ])), ]) - + +def test_parse_file(test_input, expected): parser = Parser() - actual = parser.parse('tests/in/000001.yaml') + actual = parser.parse(test_input) assert len(actual.services) == len(expected.services)