예제 #1
0
    def test_pickle(self):
        """Test pickle behaviour of position instances."""
        # setup
        import pickle

        within_pos = WithinPosition(10, left=10, right=13)
        between_pos = BetweenPosition(24, left=20, right=24)
        oneof_pos = OneOfPosition(
            1888,
            [ExactPosition(1888), ExactPosition(1901)])
        # test __getnewargs__
        self.assertEqual(within_pos.__getnewargs__(), (10, 10, 13))
        self.assertEqual(between_pos.__getnewargs__(), (24, 20, 24))
        self.assertEqual(
            oneof_pos.__getnewargs__(),
            (1888, [ExactPosition(1888),
                    ExactPosition(1901)]),
        )
        # test pickle behaviour
        within_pos2 = pickle.loads(pickle.dumps(within_pos))
        between_pos2 = pickle.loads(pickle.dumps(between_pos))
        oneof_pos2 = pickle.loads(pickle.dumps(oneof_pos))
        self.assertEqual(within_pos, within_pos2)
        self.assertEqual(between_pos, between_pos2)
        self.assertEqual(oneof_pos, oneof_pos2)
        self.assertEqual(within_pos._left, within_pos2._left)
        self.assertEqual(within_pos._right, within_pos2._right)
        self.assertEqual(between_pos._left, between_pos2._left)
        self.assertEqual(between_pos._right, between_pos2._right)
        self.assertEqual(oneof_pos.position_choices,
                         oneof_pos2.position_choices)
예제 #2
0
 def test_fuzzy(self):
     """Test fuzzy representations."""
     # check the positions alone
     exact_pos = ExactPosition(5)
     within_pos_s = WithinPosition(10, left=10, right=13)
     within_pos_e = WithinPosition(13, left=10, right=13)
     between_pos_e = BetweenPosition(24, left=20, right=24)
     before_pos = BeforePosition(15)
     after_pos = AfterPosition(40)
     self.assertEqual(int(within_pos_s), 10)
     self.assertEqual(str(within_pos_s), "(10.13)")
     self.assertEqual(int(within_pos_e), 13)
     self.assertEqual(str(within_pos_e), "(10.13)")
     self.assertEqual(int(between_pos_e), 24)
     self.assertEqual(str(between_pos_e), "(20^24)")
     self.assertEqual(str(before_pos), "<15")
     self.assertEqual(str(after_pos), ">40")
     # put these into Locations
     location1 = FeatureLocation(exact_pos, within_pos_e)
     location2 = FeatureLocation(before_pos, between_pos_e)
     location3 = FeatureLocation(within_pos_s, after_pos)
     self.assertEqual(str(location1), "[5:(10.13)]")
     self.assertEqual(str(location1.start), "5")
     self.assertEqual(str(location1.end), "(10.13)")
     self.assertEqual(str(location2), "[<15:(20^24)]")
     self.assertEqual(str(location2.start), "<15")
     self.assertEqual(str(location2.end), "(20^24)")
     self.assertEqual(str(location3), "[(10.13):>40]")
     self.assertEqual(str(location3.start), "(10.13)")
     self.assertEqual(str(location3.end), ">40")
     # --- test non-fuzzy representations
     self.assertEqual(location1.nofuzzy_start, 5)
     self.assertEqual(location1.nofuzzy_end, 13)
     self.assertEqual(location2.nofuzzy_start, 15)
     self.assertEqual(location2.nofuzzy_end, 24)
     self.assertEqual(location3.nofuzzy_start, 10)
     self.assertEqual(location3.nofuzzy_end, 40)