aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/computations
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-03-08 08:18:32 +0300
committerFrederick Muriuki Muriithi2022-03-08 08:18:32 +0300
commita7696cc668e00215e1d5af2425765451811bca9d (patch)
treecc4bb5865605f0ce2f2f0fc3fdba9f8155eb51f5 /tests/unit/computations
parente30f9a9b746f7dcdc8707e66cc65e580e6f83f47 (diff)
downloadgenenetwork3-a7696cc668e00215e1d5af2425765451811bca9d.tar.gz
Remove unused function and its tests
Diffstat (limited to 'tests/unit/computations')
-rw-r--r--tests/unit/computations/test_dictify_by_samples.py113
-rw-r--r--tests/unit/computations/test_partial_correlations.py32
2 files changed, 0 insertions, 145 deletions
diff --git a/tests/unit/computations/test_dictify_by_samples.py b/tests/unit/computations/test_dictify_by_samples.py
deleted file mode 100644
index 5cd3eca..0000000
--- a/tests/unit/computations/test_dictify_by_samples.py
+++ /dev/null
@@ -1,113 +0,0 @@
-"""Property tests for `gn3.computations.partial_correlations.dictify_by_samples`
- function"""
-from math import isnan
-from collections.abc import Sequence
-
-import pytest
-from hypothesis import given, strategies as st
-
-from gn3.computations.partial_correlations import dictify_by_samples
-
-
-def check_keys(samples, the_dict):
- """Check that all the keys in `the_dict` are strings in `samples.`"""
- return all(
- (key in samples) for key in the_dict.keys())
-
-
-def same(val1, val2):
- """
- Check that values are similar.
-
- In Python3 `float('nan') == float('nan')` always returns False. This
- function thus, compares similarity rather than direct equality for NaN
- values.
-
- `Math.isnan(None)` would throw an error, thus this function takes advantage
- of the `or` operation's short-circuit to avoid this failure in the case
- where both values are NoneType values.
- """
- return (
- (val1 is None and val2 is None) or
- (isnan(val1) and isnan(val2)) or
- (val1 == val2))
-
-def check_dict_keys_and_values(sample, value, variance, the_dict):
- """
- Check the following properties for each dict:
- - has only `sample_name`, `value` and `variance` as the keys
- - The values in the dict are the same ones in `sample`, `value` and
- `variance`.
- """
- return (
- all((key in ("sample_name", "value", "variance"))
- for key in the_dict.keys()) and
- the_dict["sample_name"] == sample and
- same(the_dict["value"], value) and
- same(the_dict["variance"], variance))
-
-def check_values(samples, values, variances, row):
- """
- Check that the values in each dict in `row` are made up from the values in
- the `samples`, `values`, and `variances` sequences, skipping all values in
- the `row` for which the sample name is an empty string.
- """
- return all(
- check_dict_keys_and_values(smp, val, var, row[smp])
- for smp, val, var in zip(samples, values, variances)
- if smp != "")
-
-generated_non_empty_samples = st.lists(
- st.text(min_size=1, max_size=15).map(
- lambda s: s.strip()))
-generated_empty_samples = st.text(
- alphabet=" \t\n\r\f\v", min_size=1, max_size=15).filter(
- lambda s: len(s.strip()) == 0)
-generated_values = st.lists(st.floats())
-generated_variances = st.lists(st.one_of(st.none(), st.floats()))
-generated_other = st.lists(st.integers())
-
-@pytest.mark.unit_test
-@given(svv=st.tuples(
- st.lists(generated_non_empty_samples),
- st.lists(generated_values),
- st.lists(generated_variances),
- st.lists(generated_other)))
-def test_dictifify_by_samples_with_nonempty_samples_strings(svv):
- """
- Test for `dictify_by_samples`.
-
- Given a sequence of sequences of sequences
-
- Check for the following properties:
- - Returns a sequence of dicts
- - Each dicts keys correspond to its index in the zeroth sequence in the
- top-level sequence
- """
- res = dictify_by_samples(svv)
- assert (
- isinstance(res, Sequence)
- and all((isinstance(elt, dict) for elt in res))
- and all(
- check_keys(svv[0][idx], row)
- for idx, row in enumerate(res))
- and all(
- check_values(svv[0][idx], svv[1][idx], svv[2][idx], row)
- for idx, row in enumerate(res)))
-
-@pytest.mark.unit_test
-@given(svv=st.tuples(
- st.lists(
- st.lists(generated_empty_samples,min_size=1),
- min_size=1),
- st.lists(st.lists(st.floats(), min_size=1), min_size=1),
- st.lists(
- st.lists(st.one_of(st.none(), st.floats()), min_size=1), min_size=1),
- st.lists(st.lists(st.integers(), min_size=1), min_size=1)))
-def test_dictify_by_samples_with_empty_samples_strings(svv):
- """
- Test that `dictify_by_samples` warns the user about providing sample names
- that are just empty strings.
- """
- with pytest.warns(RuntimeWarning):
- dictify_by_samples(svv)
diff --git a/tests/unit/computations/test_partial_correlations.py b/tests/unit/computations/test_partial_correlations.py
index ee17659..81ddbcc 100644
--- a/tests/unit/computations/test_partial_correlations.py
+++ b/tests/unit/computations/test_partial_correlations.py
@@ -10,7 +10,6 @@ from gn3.computations.partial_correlations import (
fix_samples,
control_samples,
build_data_frame,
- dictify_by_samples,
tissue_correlation,
find_identical_traits,
good_dataset_samples_indexes)
@@ -115,37 +114,6 @@ class TestPartialCorrelations(TestCase):
(6, 4, 3)))
@pytest.mark.unit_test
- def test_dictify_by_samples(self):
- """
- Test that `dictify_by_samples` generates the appropriate dict
-
- Given:
- a sequence of sequences with sample names, values and variances, as
- in the output of `gn3.partial_correlations.control_samples` or
- the output of `gn3.db.traits.export_informative`
- When:
- the sequence is passed as an argument into the
- `gn3.partial_correlations.dictify_by_sample`
- Then:
- return a sequence of dicts with keys being the values of the sample
- names, and each of who's values being sub-dicts with the keys
- 'sample_name', 'value' and 'variance' whose values correspond to the
- values passed in.
- """
- self.assertEqual(
- dictify_by_samples(
- ((("B6cC3-1", "BXD1", "BXD12", "BXD16", "BXD19", "BXD2"),
- ("BXD12", "BXD16", "BXD19", "BXD2"),
- ("B6cC3-1", "BXD1", "BXD2")),
- ((7.51879, 7.77141, 8.39265, 8.17443, 8.30401, 7.80944),
- (8.39265, 8.17443, 8.30401, 7.80944),
- (7.51879, 7.77141, 7.80944)),
- ((None, None, None, None, None, None), (None, None, None, None),
- (None, None, None)),
- (6, 4, 3))),
- dictified_control_samples)
-
- @pytest.mark.unit_test
def test_fix_samples(self):
"""
Test that `fix_samples` returns only the common samples