diff options
author | Frederick Muriuki Muriithi | 2023-01-21 03:18:26 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-01-21 03:18:26 +0300 |
commit | aee68e2a2675c225364b8e02d4e99cb0951dc89e (patch) | |
tree | 4e1372d60a8984c528a73e4a3deed50500ad9d2a /tests | |
parent | 3d04f8a28386a08a19c01f8154872fcff4936dec (diff) | |
download | genenetwork3-aee68e2a2675c225364b8e02d4e99cb0951dc89e.tar.gz |
tests: Fix linting errors
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_search.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit/test_search.py b/tests/unit/test_search.py index 487bac0..ec89a61 100644 --- a/tests/unit/test_search.py +++ b/tests/unit/test_search.py @@ -1,3 +1,4 @@ +"""Test that the search feature works as expected""" from hypothesis import given, strategies as st from pymonad.maybe import Just, Nothing import pytest @@ -8,28 +9,68 @@ from gn3.api.search import apply_si_suffix, parse_range @given(st.decimals(places=3, allow_nan=False, allow_infinity=False), st.sampled_from(["k", "K"])) def test_apply_si_suffix_kilo(mantissa, suffix): + """ + GIVEN: A string of a decimal value with up to 9 decimal places and a suffix 'K' + e.g. 45.240K - where '45.240' is the decimal values + WHEN: We apply the suffix + THEN: We get the integer value that is closest to the decimal value + multiplied by 1000 + """ assert apply_si_suffix(f"{mantissa}{suffix}") == int(mantissa * 10**3) @pytest.mark.unit_test @given(st.decimals(places=6, allow_nan=False, allow_infinity=False), st.sampled_from(["m", "M"])) def test_apply_si_suffix_mega(mantissa, suffix): + """ + GIVEN: A string of a decimal value with up to 9 decimal places and a suffix 'M' + e.g. 45.240M - where '45.240' is the decimal values + WHEN: We apply the suffix + THEN: We get the integer value that is closest to the decimal value + multiplied by 1000000 + """ assert apply_si_suffix(f"{mantissa}{suffix}") == int(mantissa * 10**6) @pytest.mark.unit_test @given(st.decimals(places=9, allow_nan=False, allow_infinity=False), st.sampled_from(["g", "G"])) def test_apply_si_suffix_giga(mantissa, suffix): + """ + GIVEN: A string of a decimal value with up to 9 decimal places and a suffix 'G' + e.g. 45.240G - where '45.240' is the decimal values + WHEN: We apply the suffix + THEN: We get the integer value that is closest to the decimal value + multiplied by 1000000000 + """ assert apply_si_suffix(f"{mantissa}{suffix}") == int(mantissa * 10**9) @pytest.mark.unit_test def test_parse_range_closed_interval(): + """ + GIVEN: An closed range as a string, with both the beginning and the ending + e.g. "foo..bar" + WHEN: we parse the range + THEN: we get both values for the beginning (Just("foo")) and the ending + (Just("bar")). + """ assert parse_range("foo..bar") == (Just("foo"), Just("bar")) @pytest.mark.unit_test def test_parse_range_left_open_interval(): + """ + GIVEN: An open range as a string, with only the ending e.g. "foo.." + WHEN: we parse the range + THEN: we get no value (Nothing) for the beginning and an actual value + (Just("bar")) for the ending + """ assert parse_range("..bar") == (Nothing, Just("bar")) @pytest.mark.unit_test def test_parse_range_right_open_interval(): + """ + GIVEN: An open range as a string, with only the beginning e.g. "foo.." + WHEN: we parse the range + THEN: we get an actual value for the beginning of the range (Just("foo")) + and no value (Nothing) for the ending of the range + """ assert parse_range("foo..") == (Just("foo"), Nothing) |