Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polymorfic #33

Merged
merged 12 commits into from
Jan 2, 2020
Prev Previous commit
Next Next commit
parametrized test
  • Loading branch information
Tishka17 committed Dec 26, 2019
commit 7ea2760ec2b2069c05f058a317e4197b4f359f61
39 changes: 24 additions & 15 deletions tests/test_literal.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import sys
from unittest import TestCase

from nose2.tools import params
from typing_extensions import Literal as CompatLiteral

from dataclass_factory import Factory

LITERALS = [CompatLiteral]
if sys.version_info >= (3, 8):
from typing import Literal
from typing import Literal as PyLiteral

ABC = Literal["a", "b", "c"]
One = Literal[1]
LITERALS.append(PyLiteral)


class TestLiteral(TestCase):
def setUp(self) -> None:
self.factory = Factory()
class TestLiteral(TestCase):
def setUp(self) -> None:
self.factory = Factory()

def test_literal_fail(self):
with self.assertRaises(ValueError):
self.factory.load("d", ABC)
with self.assertRaises(ValueError):
self.factory.load(1.0, One)
@params(*LITERALS)
def test_literal_fail(self, literal):
abc = literal["a", "b", "c"]
one = literal[1]
with self.assertRaises(ValueError):
self.factory.load("d", abc)
with self.assertRaises(ValueError):
self.factory.load(1.0, one)

def test_literal(self):
self.assertEqual(self.factory.load("a", ABC), "a")
self.assertEqual(self.factory.load("b", ABC), "b")
self.assertEqual(self.factory.load(1, One), 1)
@params(*LITERALS)
def test_literal(self, literal):
abc = literal["a", "b", "c"]
one = literal[1]
self.assertEqual(self.factory.load("a", abc), "a")
self.assertEqual(self.factory.load("b", abc), "b")
self.assertEqual(self.factory.load(1, one), 1)
24 changes: 0 additions & 24 deletions tests/test_literal_compat.py

This file was deleted.