Beispiel #1
0
    def test___sub__(self):
        assert SequenceRange(5, 20) - SequencePoint(3) == SequenceRange(3, 18)
        with pytest.raises(ValueError):
            # 20 - 5, 20 - 10 -> 15, 10 = makes no sense!!
            (SequencePoint(20) - SequenceRange(5, 10)).validate()

        assert SequenceRange(10, 15) - SequencePoint(5) == SequenceRange(6, 11)
Beispiel #2
0
 def test_adding_1_2_and_3_twice_to_a_set_only_changes_length_by_3(
         self):
     my_set = set()
     self.parent._assert_hash(my_set, SequencePoint(1), 0, 1)
     self.parent._assert_hash(my_set, SequencePoint(1), 1, 1)
     self.parent._assert_hash(my_set, SequencePoint(2), 1, 2)
     self.parent._assert_hash(my_set, SequencePoint(2), 2, 2)
     self.parent._assert_hash(my_set, SequencePoint(3), 2, 3)
Beispiel #3
0
 def test_less_or_greather_than_comarison_to_string(self):
     with pytest.raises(TypeError):
         SequencePoint(1) < "Wrong type!!"
     with pytest.raises(TypeError):
         "Wrong type!!" < SequencePoint(1)
     with pytest.raises(TypeError):
         SequencePoint(1) > "Wrong type!!"
     with pytest.raises(TypeError):
         "Wrong type!!" > SequencePoint(1)
Beispiel #4
0
 def test___add__(self):
     assert SequenceRange(2, 3) + SequencePoint(2) == SequenceRange(3, 4)
     assert SequencePoint(2) + SequenceRange(2, 3) == SequenceRange(3, 4)
     assert SequenceRange(2, 3) + SequencePoint(2) + 5 == SequenceRange(
         8, 9)
     assert 5 + SequenceRange(2, 3) + SequencePoint(2) == SequenceRange(
         8, 9)
     assert SequenceRange(2, 3) + 5 + SequencePoint(2) == SequenceRange(
         8, 9)
Beispiel #5
0
 def test_1_is_less_than_5_which_is_less_than_9(self):
     sp1 = SequencePoint(1)
     sp5 = SequencePoint(5)
     sp9 = SequencePoint(9)
     assert sp1 < sp5 < sp9
     assert sp9 > sp5 > sp1
     assert sp1 < 5 < sp9
     assert sp9 > 5 > sp1
     assert 1 < sp5 < 9
     assert 9 > sp5 > 1
Beispiel #6
0
 def test_1_is_less_than_or_equal_to_5_which_is_less_than_or_equal_9(
         self):
     sp1 = SequencePoint(1)
     sp5 = SequencePoint(5)
     sp9 = SequencePoint(9)
     assert sp1 <= sp5 <= sp9
     assert sp9 >= sp5 >= sp1
     assert sp1 <= 5 <= sp9
     assert sp9 >= 5 >= sp1
     assert 1 <= sp5 <= 9
     assert 9 >= sp5 >= 1
Beispiel #7
0
 def test_immutability(self):
     s = SequenceRange(1, 2)
     with pytest.raises(AttributeError):
         s.pos = (1, 2)
     with pytest.raises(AttributeError):
         s.index = (1, 2)
     with pytest.raises(AttributeError):
         s.slice = (1, 2)
     with pytest.raises(AttributeError):
         s.start = SequencePoint(2)
     with pytest.raises(AttributeError):
         s.stop = SequencePoint(2)
Beispiel #8
0
    def test___iter__(self):
        sr = SequenceRange(5, 10)
        sr_points = list(sr)  # should be equivalent to list(sr.__iter__())
        assert sr.length == len(sr_points)
        assert sr_points[0].pos == sr.start.pos
        assert sr_points[-1].pos == sr.stop.pos

        assert list(SequenceRange(5, 5))[0] == SequencePoint(5)
Beispiel #9
0
            def test_point_5_is_equal_to_5_and_not_greater_or_smaller(self):
                assert not 5 < SequencePoint(5)
                assert not 5 > SequencePoint(5)
                assert not SequencePoint(5) < 5
                assert not SequencePoint(5) > 5

                assert 5 <= SequencePoint(5)
                assert 5 >= SequencePoint(5)
                assert SequencePoint(5) <= 5
                assert SequencePoint(5) >= 5
Beispiel #10
0
    def test___sub__(self):
        # cls(1) has index = 0, pos = 1
        cls = self.test_class
        assert cls(1) - cls(1) == cls(1)  # because index 0 - 0 = 0
        assert cls(2) - 1 == cls(1)  # because index 1 - 1 = 0
        #  assert -1 + cls(1) == cls(2)  # because index 1 + 0 = 1
        assert cls(2) - cls(2) == cls(1)  # because 1 - 1 = 0
        assert cls(10) - cls(10) == cls(1)  # because 9 - 9 = 0
        assert 10 - cls(2) == cls(10)  # because 10 - 1 = 9
        assert cls(10) - cls(1) == cls(10)  # because 9 - 0 = 9

        # because 1 - 2 = -1 -> index = -1, pos = 0 -> invalid pos
        with pytest.raises(ValueError):
            (cls(2) - 2).validate()
        with pytest.raises(ValueError):
            (SequencePoint(2) - SequencePoint(3)).validate()
        with pytest.raises(ValueError):
            (1 - SequencePoint(3)).validate()
        with pytest.raises(Exception):
            cls(10) - math.nan
        with pytest.raises(Exception):
            math.nan - cls(10)
Beispiel #11
0
    class TestImutability:
        s = SequencePoint(5)

        def test_changing_pos_raises_attributeerror(self):
            with pytest.raises(AttributeError):
                self.s.pos = 5

        def test_changing_index_raises_attributeerror(self):
            with pytest.raises(AttributeError):
                self.s.index = 5

        def test_constructor_returns_first_argument_if_it_is_already_an_instance(
                self):
            assert self.s is SequencePoint(self.s)
            assert self.s is not SequencePoint(5)
Beispiel #12
0
    def test_contains(self):
        #          0        10        20
        #          0123456789012345678901 #
        #  self  = -----ELVISLIVES        #
        #  item1 = ----------L----        <--- part=all -> True,  part=any -> True
        #  item2 = ----------LIVE-        <--- part=all -> True,  part=any -> True
        #  item3 = ----------LIVESANDDIES <--- part=all -> False, part=any -> True
        #  item4 = ELVENELVISLIVESANDDIES <--- part=all -> False, part=any -> True
        #  item5 = ------------------D--- <--- part=all -> False, part=any -> False
        #  item6 = ------------------DIES <--- part=all -> False, part=any -> False
        #  item7 = ----N----------------- <--- part=all -> False, part=any -> False
        #  item8 = ELVEN----------------- <--- part=all -> False, part=any -> False

        _self = SequenceRange(5, 14)
        item1 = SequencePoint(10)
        item2 = SequenceRange(10, 13)
        item3 = SequenceRange(10, 21)
        item4 = SequenceRange(1, 21)
        item5 = SequenceRange(18, 21)
        item6 = SequenceRange(18, 21)
        item7 = SequencePoint(4)
        item8 = SequenceRange(1, 4)

        for item in (item1, item2):
            assert _self.contains(item, part=all)
        for item in (item3, item4, item5, item6, item7, item8):
            assert not _self.contains(item3, part=all)

        for item in (item1, item2, item3, item4):
            assert _self.contains(item, part=any)
        for item in (item5, item6, item7, item8):
            assert not _self.contains(item, part=any)

        # make sure it answers False to silly things
        assert not _self.contains('xyz')
        assert not _self.contains(object())
Beispiel #13
0
 def test2b(self):
     assert SequenceRange(2) + SequencePoint(2) == 3
Beispiel #14
0
 def test_it_is_not_inside_a_container(self):
     assert SequencePoint(1) not in (5, SequencePoint(10))
Beispiel #15
0
 def test_conversion(self):
     assert SequenceRange(1, 1) == SequenceRange(SequencePoint(1))
     assert SequenceRange(1, 2) == SequenceRange(SequencePoint(1),
                                                 SequencePoint(2))
     assert SequenceRange(1, 2) == SequenceRange(SequencePoint(1), 2)
     assert SequenceRange(1, 2) == SequenceRange(1, SequencePoint(2))
Beispiel #16
0
 def test_its_numeric_representation_is_not_in_a_container(self):
     assert SequencePoint(1) not in (5, 10)
Beispiel #17
0
 def when_its_a_number_different_from_its_numeric_representation_is_searched(
         self):
     assert 1 not in (5, SequencePoint(10))
Beispiel #18
0
 def test___str__(self):
     assert str(SequencePoint(10)) == str(10)
Beispiel #19
0
 def test_constructor_returns_first_argument_if_it_is_already_an_instance(
         self):
     assert self.s is SequencePoint(self.s)
     assert self.s is not SequencePoint(5)
Beispiel #20
0
 def test_equal_or_not_equal_comparison_non_numeric_string(self):
     assert not "Wrong type!!" == SequencePoint(1)
     assert not SequencePoint(1) == "Wrong type!!"
     assert "Wrong type!!" != SequencePoint(1)
     assert SequencePoint(1) != "Wrong type!!"
Beispiel #21
0
 def test_point_1_and_1_hits_the_same_in_a_dictionary_lookup(self):
     lookup = {1: 1, SequencePoint(5): 5}
     assert lookup[SequencePoint(1)] == lookup[1] == 1
     assert lookup[SequencePoint(5)] == lookup[5] == 5
Beispiel #22
0
 def test_can_not_create_a_sequence_from_range_if_start_and_stop_are_different(
         self):
     with pytest.raises(TypeError):
         assert SequencePoint(SequenceRange(10, 12))
Beispiel #23
0
 def test_is_hashable(self):
     hash(SequencePoint(1))
Beispiel #24
0
 def test___repr__(self):
     assert repr(SequencePoint(10)) == "SequencePoint(10)"
Beispiel #25
0
 def when_its_numeric_representation_is_searched_for_in_a_container_containing_it(
         self):
     assert 1 in (5, SequencePoint(1))
Beispiel #26
0
    def test_init(self, glucagon_peptides, glucagon_seq):
        # simple tests
        p = SequenceRange(self.pep_start,
                          self.pep_stop,
                          full_sequence=self.protein_seq)
        assert p.pos == (self.pep_start, self.pep_stop)
        assert self.pep_seq == p.seq
        self._assert(p, self.pep_seq, self.protein_seq)

        # pep_stop infered from len(pep_seq)
        assert p == SequenceRange(self.pep_start, seq=self.pep_seq)

        # has to be valid numbers!
        with pytest.raises(ValueError):
            SequenceRange(0, 0)
        with pytest.raises(ValueError):
            SequenceRange(-10, 10)
        with pytest.raises(ValueError):
            SequenceRange(10, -10)
        with pytest.raises(ValueError):
            SequenceRange(0, 10)
        with pytest.raises(ValueError):
            SequenceRange(10, 0)
        with pytest.raises(ValueError):
            SequenceRange(15, 10)

        # if start is a abc.Sequence, then stop has to be None
        with pytest.raises(ValueError):
            SequenceRange((5, 10), 10)
        with pytest.raises(ValueError):
            SequenceRange(SequenceRange(5, 10), 10)
        with pytest.raises(ValueError):
            SequenceRange((SequencePoint(5), SequencePoint(10)),
                          SequencePoint(10))

        # ensure it can cast itself, just like int(int(1)) == int(1)
        assert SequenceRange(SequenceRange(1)) == SequenceRange(1)

        # all peptides
        for (start, stop, seq) in glucagon_peptides:
            p = SequenceRange(start, stop, seq)
            self._assert(p, seq, glucagon_seq)

        # if no stop, then the range is 1 amino acid
        p = SequenceRange(self.pep_start)
        assert p.start.pos == p.stop.pos
        assert self.protein_seq[p.slice] == 'L'
        assert SequenceRange(10) == SequenceRange('10')
        assert SequenceRange(10, 20) == SequenceRange('10:20')
        assert SequenceRange(10, 20) == SequenceRange(b'10:20')

        # make sure that a new object is created if extra annotations are avalible
        with_seq = SequenceRange(self.pep_start,
                                 self.pep_stop,
                                 full_sequence=self.protein_seq)
        without_seq = SequenceRange(with_seq.start, with_seq.stop)
        p = SequenceRange(without_seq, seq=with_seq.seq)
        assert p.seq is not None
        assert p.seq == with_seq.seq == self.pep_seq
        assert without_seq.seq is None

        # make sure seq is not lost (old bug, should not reapear!)
        with_seq2 = SequenceRange(with_seq, seq='FAKE')
        assert with_seq2.seq == 'FAKE'
        assert with_seq.seq == self.pep_seq

        # make sure to throw warnings if seq or full_sequence are mallformed
        with pytest.raises(ValueError):  # seq to short
            SequenceRange(1, 10, seq='AAA')
        with pytest.raises(ValueError):  # seq to long
            SequenceRange(1, 10, seq='A' * 20)

        with pytest.raises(ValueError):  # full_sequence to short
            SequenceRange(1, 10, full_sequence='AAA')
Beispiel #27
0
 def test_can_create_a__point_from_range_if_start_and_stop_are_the_same(
         self):
     assert SequencePoint(SequenceRange(10)) == SequencePoint(10)
Beispiel #28
0
 def test_valid_points_are_larger_than_negative_numbers(self):
     assert -1 < SequencePoint(5)
     assert -1 <= SequencePoint(5)
Beispiel #29
0
 def test_hashes_to_the_same_as_integers(self):
     assert hash(SequencePoint(1)) == hash(1)
     assert hash(SequencePoint(5)) == hash(5)
     assert hash(SequencePoint(9)) == hash(9)
Beispiel #30
0
 def test_created_from_different_data(self):
     assert SequencePoint(1) != SequencePoint(5)
     assert SequencePoint(5) != SequencePoint(1)