From 23241365e38129262e741ecf151d3579bb85af7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Turin=CC=83o?= Date: Thu, 29 Jul 2021 11:06:46 +0200 Subject: [PATCH] fix: fixing tests and circular dependencies --- key_set/all.py | 23 --------- key_set/all_except_some.py | 30 ----------- key_set/base.py | 94 ++++++++++++++++++++++++++++++++++- key_set/none.py | 23 --------- key_set/some.py | 27 ---------- key_set/utils.py | 14 ------ tests/test_all.py | 23 +++++++++ tests/test_all_except_some.py | 24 +++++++++ tests/test_elements.py | 5 +- tests/test_none.py | 23 +++++++++ tests/test_some.py | 25 ++++++++++ tests/test_utils.py | 36 -------------- 12 files changed, 189 insertions(+), 158 deletions(-) delete mode 100644 key_set/all.py delete mode 100644 key_set/all_except_some.py delete mode 100644 key_set/none.py delete mode 100644 key_set/some.py delete mode 100644 key_set/utils.py create mode 100644 tests/test_all.py create mode 100644 tests/test_all_except_some.py create mode 100644 tests/test_none.py create mode 100644 tests/test_some.py delete mode 100644 tests/test_utils.py diff --git a/key_set/all.py b/key_set/all.py deleted file mode 100644 index 2ee0c86..0000000 --- a/key_set/all.py +++ /dev/null @@ -1,23 +0,0 @@ -from key_set.base import KeySet -from key_set.enum import KeySetType -from key_set.none import KeySetNone - - -class KeySetAll(KeySet): - """Represents the ALL sets: π•Œ (the entirety of possible keys).""" - - def key_set_type(self) -> KeySetType: - """Returns the KeySetType that describes the set.""" - return KeySetType.ALL - - def elements(self) -> set[str]: - """Returns an empty set.""" - return set() - - def represents_all(self) -> bool: - """Returns true if the set is a ALL KeySet.""" - return True - - def invert(self) -> KeySetNone: - """Returns a new KeySet NONE.""" - return KeySetNone() diff --git a/key_set/all_except_some.py b/key_set/all_except_some.py deleted file mode 100644 index f9f169d..0000000 --- a/key_set/all_except_some.py +++ /dev/null @@ -1,30 +0,0 @@ -from key_set.base import KeySet -from key_set.enum import KeySetType -from key_set.some import KeySetSome - - -class KeySetAllExceptSome(KeySet): - """Represents the ALL_EXCEPT_SOME sets: the complementary of a concrete set. - - Includes all the elements except the given ones (`A' = {x ∈ π•Œ | x βˆ‰ A}`). - """ - - def __init__(self, elements: set[str]): - """Requires the set of elements of the concrete set.""" - self._elements = set(elements) - - def key_set_type(self) -> KeySetType: - """Returns the KeySetType that describes the set.""" - return KeySetType.ALL_EXCEPT_SOME - - def elements(self) -> set[str]: - """Returns a copy of the set of the elements of the concrete set.""" - return set(self._elements) - - def represents_all_except_some(self) -> bool: - """Returns true if the set is a ALL_EXCEPT_SOME KeySet.""" - return True - - def invert(self) -> KeySetSome: - """Returns a new KeySet SOME.""" - return KeySetSome(self.elements()) diff --git a/key_set/base.py b/key_set/base.py index 13ba180..f3e7976 100644 --- a/key_set/base.py +++ b/key_set/base.py @@ -1,7 +1,8 @@ +from __future__ import annotations from abc import ABC, abstractmethod # abc is a builtin module, we have to import ABC and abstractmethod -from key_set.enum import KeySetType +from .enum import KeySetType class KeySet(ABC): # Inherit from ABC(Abstract base class) @@ -44,3 +45,94 @@ def invert(self): Some <-> AllExceptSome """ pass + + +class KeySetAll(KeySet): + """Represents the ALL sets: π•Œ (the entirety of possible keys).""" + + def key_set_type(self) -> KeySetType: + """Returns the KeySetType that describes the set.""" + return KeySetType.ALL + + def elements(self) -> set[str]: + """Returns an empty set.""" + return set() + + def represents_all(self) -> bool: + """Returns true if the set is a ALL KeySet.""" + return True + + def invert(self) -> KeySetNone: + """Returns a new KeySet NONE.""" + return KeySetNone() + + +class KeySetNone(KeySet): + """Represents the NONE sets: ΓΈ (empty set).""" + + def key_set_type(self) -> KeySetType: + """Returns the KeySetType that describes the set.""" + return KeySetType.NONE + + def elements(self) -> set[str]: + """Returns an empty set.""" + return set() + + def represents_none(self) -> bool: + """Returns true if the set is a NONE KeySet.""" + return True + + def invert(self) -> KeySetAll: + """Returns a new KeySet ALL.""" + return KeySetAll() + + +class KeySetSome(KeySet): + """Represents the SOME sets: a concrete set (`A βŠ‚ π•Œ`).""" + + def __init__(self, elements: set[str]): + """Requires the set of elements of the concrete set.""" + self._elements = set(elements) + + def key_set_type(self) -> KeySetType: + """Returns the KeySetType that describes the set.""" + return KeySetType.SOME + + def elements(self) -> set[str]: + """Returns a copy of the set of the elements of the concrete set.""" + return set(self._elements) + + def represents_some(self) -> bool: + """Returns true if the set is a SOME KeySet.""" + return True + + def invert(self) -> KeySetAllExceptSome: + """Returns a new KeySet ALL_EXCEPT_SOME.""" + return KeySetAllExceptSome(self.elements()) + + +class KeySetAllExceptSome(KeySet): + """Represents the ALL_EXCEPT_SOME sets: the complementary of a concrete set. + + Includes all the elements except the given ones (`A' = {x ∈ π•Œ | x βˆ‰ A}`). + """ + + def __init__(self, elements: set[str]): + """Requires the set of elements of the concrete set.""" + self._elements = set(elements) + + def key_set_type(self) -> KeySetType: + """Returns the KeySetType that describes the set.""" + return KeySetType.ALL_EXCEPT_SOME + + def elements(self) -> set[str]: + """Returns a copy of the set of the elements of the concrete set.""" + return set(self._elements) + + def represents_all_except_some(self) -> bool: + """Returns true if the set is a ALL_EXCEPT_SOME KeySet.""" + return True + + def invert(self) -> KeySetSome: + """Returns a new KeySet SOME.""" + return KeySetSome(self.elements()) diff --git a/key_set/none.py b/key_set/none.py deleted file mode 100644 index d79ac3a..0000000 --- a/key_set/none.py +++ /dev/null @@ -1,23 +0,0 @@ -from key_set.all import KeySetAll -from key_set.base import KeySet -from key_set.enum import KeySetType - - -class KeySetNone(KeySet): - """Represents the NONE sets: ΓΈ (empty set).""" - - def key_set_type(self) -> KeySetType: - """Returns the KeySetType that describes the set.""" - return KeySetType.NONE - - def elements(self) -> set[str]: - """Returns an empty set.""" - return set() - - def represents_none(self) -> bool: - """Returns true if the set is a NONE KeySet.""" - return True - - def invert(self) -> KeySetAll: - """Returns a new KeySet ALL.""" - return KeySetAll() diff --git a/key_set/some.py b/key_set/some.py deleted file mode 100644 index 63b5460..0000000 --- a/key_set/some.py +++ /dev/null @@ -1,27 +0,0 @@ -from key_set.all_except_some import KeySetAllExceptSome -from key_set.base import KeySet -from key_set.enum import KeySetType - - -class KeySetSome(KeySet): - """Represents the SOME sets: a concrete set (`A βŠ‚ π•Œ`).""" - - def __init__(self, elements: set[str]): - """Requires the set of elements of the concrete set.""" - self._elements = set(elements) - - def key_set_type(self) -> KeySetType: - """Returns the KeySetType that describes the set.""" - return KeySetType.SOME - - def elements(self) -> set[str]: - """Returns a copy of the set of the elements of the concrete set.""" - return set(self._elements) - - def represents_some(self) -> bool: - """Returns true if the set is a SOME KeySet.""" - return True - - def invert(self) -> KeySetAllExceptSome: - """Returns a new KeySet ALL_EXCEPT_SOME.""" - return KeySetAllExceptSome(self.elements()) diff --git a/key_set/utils.py b/key_set/utils.py deleted file mode 100644 index 034d68b..0000000 --- a/key_set/utils.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -"""Utility functions.""" - - -def add_two_numbers( - number_left: int = None, - number_right: int = None, -) -> int: - """Add two numbers.""" - if not number_left: - raise ValueError('Input number_left must be set.') - if not number_right: - raise ValueError('Input number_right must be set.') - return number_left + number_right diff --git a/tests/test_all.py b/tests/test_all.py new file mode 100644 index 0000000..7be177e --- /dev/null +++ b/tests/test_all.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +import __future__ # noqa: F401 + +from key_set.base import KeySetAll + + +class TestAll: # noqa: D101 + + def test_represents(self) -> None: + ks = KeySetAll() + assert ks.represents_all() + assert not ks.represents_none() + assert not ks.represents_some() + assert not ks.represents_all_except_some() + + def test_invert(self) -> None: + ks = KeySetAll() + actual = ks.invert() + assert actual.represents_none() + + def test_elements(self) -> None: + ks = KeySetAll() + assert ks.elements() == set() diff --git a/tests/test_all_except_some.py b/tests/test_all_except_some.py new file mode 100644 index 0000000..9bc5860 --- /dev/null +++ b/tests/test_all_except_some.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +import __future__ # noqa: F401 + +from key_set.base import KeySetAllExceptSome + + +class TestAllExceptSome: # noqa: D101 + + def test_represents(self) -> None: + ks = KeySetAllExceptSome({'a', 'b'}) + assert ks.represents_all_except_some() + assert not ks.represents_none() + assert not ks.represents_all() + assert not ks.represents_some() + + def test_invert(self) -> None: + ks = KeySetAllExceptSome({'a', 'b'}) + actual = ks.invert() + assert actual.represents_some() + assert actual.elements() == {'a', 'b'} + + def test_elements(self) -> None: + ks = KeySetAllExceptSome({'a', 'b'}) + assert ks.elements() == {'a', 'b'} diff --git a/tests/test_elements.py b/tests/test_elements.py index 87248b1..0e9331c 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -2,10 +2,7 @@ import __future__ # noqa: F401 import key_set # noqa: F401 -from key_set.all import KeySetAll -from key_set.all_except_some import KeySetAllExceptSome -from key_set.none import KeySetNone -from key_set.some import KeySetSome +from key_set.base import KeySetAll, KeySetNone, KeySetSome, KeySetAllExceptSome class TestElements: # noqa: D101 diff --git a/tests/test_none.py b/tests/test_none.py new file mode 100644 index 0000000..c1400b4 --- /dev/null +++ b/tests/test_none.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +import __future__ # noqa: F401 + +from key_set.base import KeySetNone + + +class TestNone: # noqa: D101 + + def test_represents(self) -> None: + ks = KeySetNone() + assert ks.represents_none() + assert not ks.represents_all() + assert not ks.represents_some() + assert not ks.represents_all_except_some() + + def test_invert(self) -> None: + ks = KeySetNone() + actual = ks.invert() + assert actual.represents_all() + + def test_elements(self) -> None: + ks = KeySetNone() + assert ks.elements() == set() diff --git a/tests/test_some.py b/tests/test_some.py new file mode 100644 index 0000000..67d9b50 --- /dev/null +++ b/tests/test_some.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +import __future__ # noqa: F401 + +import key_set # noqa: F401 +from key_set.base import KeySetSome + + +class TestSome: # noqa: D101 + + def test_represents(self) -> None: + ks = KeySetSome({'a', 'b'}) + assert ks.represents_some() + assert not ks.represents_none() + assert not ks.represents_all() + assert not ks.represents_all_except_some() + + def test_invert(self) -> None: + ks = KeySetSome({'a', 'b'}) + actual = ks.invert() + assert actual.represents_all_except_some() + assert actual.elements() == {'a', 'b'} + + def test_elements(self) -> None: + ks = KeySetSome({'a', 'b'}) + assert ks.elements() == {'a', 'b'} diff --git a/tests/test_utils.py b/tests/test_utils.py deleted file mode 100644 index 1434de0..0000000 --- a/tests/test_utils.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -"""Basic test suite. - -There are some 'noqa: F401' in this file to just test the isort import sorting -along with the code formatter. -""" - -import __future__ # noqa: F401 - -import json # noqa: F401 -from os import path # noqa: F401 -from re import IGNORECASE, sub # noqa: F401 - -import pytest - -import key_set # noqa: F401 -from key_set.utils import add_two_numbers - - -class TestUtils: # noqa: D101 - - @pytest.mark.parametrize('number_left, number_right', [ - (None, 1), (1, None), (None, None) - ]) - def test_add_two_numbers_no_input( - self, - number_left: int, - number_right: int - ) -> None: - """Basic input validation.""" - with pytest.raises(ValueError): - add_two_numbers(number_left, number_right) - - def test_add_two_numbers_regular_input(self) -> None: - """Basic asserting test.""" - assert add_two_numbers(2, 3) == 5