File: test_expand_attributes.py

package info (click to toggle)
python-gtfparse 1.3.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: python: 583; makefile: 12; sh: 8
file content (36 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (2)
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
from gtfparse import expand_attribute_strings

def test_attributes_in_quotes():
    attributes = [
        "gene_id \"ENSG001\"; tag \"bogotron\"; version \"1\";",
        "gene_id \"ENSG002\"; tag \"wolfpuppy\"; version \"2\";"
    ]
    parsed_dict = expand_attribute_strings(attributes)
    assert list(sorted(parsed_dict.keys())) == ["gene_id", "tag", "version"]
    assert parsed_dict["gene_id"] == ["ENSG001", "ENSG002"]
    assert parsed_dict["tag"] == ["bogotron", "wolfpuppy"]
    assert parsed_dict["version"] == ["1", "2"]


def test_attributes_without_quotes():
    attributes = [
        "gene_id ENSG001; tag bogotron; version 1;",
        "gene_id ENSG002; tag wolfpuppy; version 2"
    ]
    parsed_dict = expand_attribute_strings(attributes)
    assert list(sorted(parsed_dict.keys())) == ["gene_id", "tag", "version"]
    assert parsed_dict["gene_id"] == ["ENSG001", "ENSG002"]
    assert parsed_dict["tag"] == ["bogotron", "wolfpuppy"]
    assert parsed_dict["version"] == ["1", "2"]


def test_optional_attributes():
    attributes = [
        "gene_id ENSG001; sometimes-present bogotron;",
        "gene_id ENSG002;",
        "gene_id ENSG003; sometimes-present wolfpuppy;",
    ]
    parsed_dict = expand_attribute_strings(attributes)
    assert list(sorted(parsed_dict.keys())) == ["gene_id", "sometimes-present"]
    assert parsed_dict["gene_id"] == ["ENSG001", "ENSG002", "ENSG003"]
    assert parsed_dict["sometimes-present"] == ["bogotron", "", "wolfpuppy"]