File: helpers_test.py

package info (click to toggle)
python-gffutils 0.13-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,164 kB
  • sloc: python: 5,557; makefile: 62; sh: 13
file content (50 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import unittest
from gffutils import helpers
from gffutils import feature


class Test(unittest.TestCase):
    def test_merge_attributes(self):
        """
        Tests all possible cases of merging two dictionaries together
        """
        x = {"foo": [1], "baz": 1, "buz": [1], "biz": 1, "boo": [1]}
        y = {"bar": [2], "baz": 2, "buz": [2], "biz": 1, "boo": [1]}
        test = helpers.merge_attributes(x, y)

        for k, v in list(test.items()):
            test[k] = sorted(v)

        true = {
            "foo": [1],
            "bar": [2],
            "baz": [1, 2],
            "boo": [1],
            "buz": [1, 2],
            "biz": [1],
        }
        self.assertDictEqual(test, true)

    def test_merge_Attributes(self):
        f1 = feature.feature_from_line(
            "chr2L . testing 1 10 . + . foo=1; baz=1; buz=1; biz=1; boo=1;",
            strict=False,
        )
        f2 = feature.feature_from_line(
            "chr2L . testing 1 10 . + . bar=2; baz=2; buz=2; biz=1; boo=1;",
            strict=False,
        )
        test = helpers.merge_attributes(f1.attributes, f2.attributes)

        for k, v in list(test.items()):
            test[k] = sorted(v)

        true = {
            "foo": ["1"],
            "bar": ["2"],
            "baz": ["1", "2"],
            "boo": ["1"],
            "buz": ["1", "2"],
            "biz": ["1"],
        }
        self.assertDictEqual(test, true)