def test_set_fuzzy(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) f.fuzzy = [(False, False), (False, False)] self.assertEqual(f.fuzzy, [(False, False), (False, False)])
def test_get_metadata(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) f.metadata['name'] = 'sagB' self.assertEqual(f.metadata, {'name': 'sagB', 'function': 'transport'})
def test_set_metadata_bad(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) for value in [1, '', None]: with self.assertRaises(TypeError): f.metadata = value
def test_set_bounds(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) f.bounds = [(4, 7), (1, 3)] self.assertEqual(f.bounds, [(1, 3), (4, 7)]) self.assertEqual(f.fuzzy, [(False, False), (False, False)]) self.assertEqual(self.im._is_stale_tree, True)
def test_get_on_dropped(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2)], fuzzy=[(True, False)], metadata={'name': 'sagA'}) f.drop() self.assertEqual(f.fuzzy, [(True, False)]) self.assertEqual(f.bounds, [(1, 2)]) self.assertEqual(f.metadata, {'name': 'sagA'})
def test_reverse(self): self.im_2._reverse() Interval( interval_metadata=self.im_empty, bounds=[(0, 6), (8, 9)], metadata={'gene': 'sagA', 'bound': 0}) Interval( interval_metadata=self.im_empty, bounds=[(5, 7)], metadata={'gene': 'sagB', 'bound': 0, 'spam': [0]}) self.assertEqual(self.im_2, self.im_empty)
def test_init_out_of_bounds(self): with self.assertRaises(ValueError): Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 101)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) with self.assertRaises(ValueError): Interval(interval_metadata=self.im, bounds=[(-1, 2), (4, 6)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'})
def test_repr(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2)], metadata={'name': 'sagA'}) exp = (r"Interval\(interval_metadata=<[0-9]+>, bounds=\[\(1, 2\)\]," " fuzzy=\[\(False, False\)\], metadata={'name': 'sagA'}\)") obs = repr(f) self.assertRegex(obs, exp) # test for dropped f.drop() exp = (r"Interval\(dropped=True, bounds=\[\(1, 2\)\]," " fuzzy=\[\(False, False\)\], metadata={'name': 'sagA'}\)") obs = repr(f) self.assertRegex(obs, exp)
def test_set_bounds_bad(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) for value in [1, 's']: with self.assertRaises(TypeError): f.bounds = value for value in [[(-1, 2)], # start < lower_bound [(1, 101)], # end > upper_bound [(3, 1)], # start < end [('s', 1)], (), None]: # invalid values with self.assertRaises(ValueError): f.bounds = value
def test_drop(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2)], metadata={'name': 'sagA'}) f.drop() self.assertTrue(f._interval_metadata is None) self.assertTrue(f.dropped) self.assertTrue(f.bounds, [(1, 2)]) self.assertTrue(f.metadata, {'name': 'sagA'}) # test the idempotence f.drop() self.assertTrue(f._interval_metadata is None) self.assertTrue(f.dropped) self.assertTrue(f.bounds, [(1, 2)]) self.assertTrue(f.metadata, {'name': 'sagA'})
def test_init_default(self): f = Interval(self.im, bounds=[(0, 2), (4, self.upper_bound)]) self.assertTrue(f._interval_metadata is not None) self.assertListEqual(f.bounds, [(0, 2), (4, self.upper_bound)]) self.assertListEqual(f.fuzzy, [(False, False), (False, False)]) self.assertDictEqual(f.metadata, {})
def test_set_bounds_bad(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={'name': 'sagA', 'function': 'transport'}) for value in [1, 's']: with self.assertRaises(TypeError): f.bounds = value for value in [[(-1, 2)], # start < lower_bound [(1, 101)], # end > upper_bound [(3, 1)], # start < end [(1, 1)], # start == end [('s', 1)], (), None]: # invalid values with self.assertRaises(ValueError): f.bounds = value
def test_init_no_interval_metadata(self): with self.assertRaises(TypeError): Interval(interval_metadata=None, bounds=[(4, 7)], metadata={ 'name': 'sagA', 'function': 'transport' })
def setUp(self): self.upper_bound = 10 self.im_empty = IntervalMetadata(self.upper_bound) self.im_1 = IntervalMetadata(self.upper_bound) self.im_1_1 = Interval( interval_metadata=self.im_1, bounds=[(1, 2), (4, self.upper_bound)], metadata={'gene': 'sagA', 'bound': 0}) self.im_2 = IntervalMetadata(self.upper_bound) self.im_2_1 = Interval( interval_metadata=self.im_2, bounds=[(1, 2), (4, self.upper_bound)], metadata={'gene': 'sagA', 'bound': 0}) self.im_2_2 = Interval( interval_metadata=self.im_2, bounds=[(3, 5)], metadata={'gene': 'sagB', 'bound': 0, 'spam': [0]})
def test_init_bad_fuzzy(self): with self.assertRaises(ValueError): Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(False, False)], metadata={ 'name': 'sagA', 'function': 'transport' })
def test_init_iterables(self): f = Interval(interval_metadata=self.im, bounds=((1, 2), (4, 7)), fuzzy=((True, False), (False, False)), metadata={'name': 'sagA', 'function': 'transport'}) self.assertTrue(f._interval_metadata is not None) self.assertListEqual(f.bounds, [(1, 2), (4, 7)]) self.assertListEqual(f.fuzzy, [(True, False), (False, False)]) self.assertDictEqual(f.metadata, {'name': 'sagA', 'function': 'transport'})
def test_init_bounds_scrambled(self): f = Interval(interval_metadata=self.im, bounds=[(4, 7), (1, 2)], fuzzy=[(True, False), (False, True)], metadata={'name': 'sagA', 'function': 'transport'}) self.assertTrue(f._interval_metadata is not None) self.assertListEqual(f.bounds, [(1, 2), (4, 7)]) self.assertListEqual(f.fuzzy, [(False, True), (True, False)]) self.assertDictEqual(f.metadata, {'name': 'sagA', 'function': 'transport'})
def test_eq(self): f0 = Interval(interval_metadata=self.im, bounds=[(4, 7), (1, 2)], fuzzy=[(False, False), (True, False)], metadata={ 'name': 'sagA', 'function': 'transport' }) f1 = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={ 'name': 'sagA', 'function': 'transport' }) f2 = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={ 'name': 'sagA', 'function': 'transport' }) f3 = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, True), (False, False)], metadata={ 'name': 'sagA', 'function': 'transport' }) f4 = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 8)], fuzzy=[(True, False), (False, False)], metadata={ 'name': 'sagA', 'function': 'transport' }) f5 = Interval(interval_metadata=self.im, bounds=[(1, 2), (4, 7)], fuzzy=[(True, False), (False, False)], metadata={ 'name': 'sagB', 'function': 'transport' }) # scramble bounds/fuzzy self.assertReallyEqual(f0, f1) self.assertReallyEqual(f2, f1) # diff fuzzy self.assertReallyNotEqual(f1, f3) # diff bounds self.assertReallyNotEqual(f1, f4) # diff metadata self.assertReallyNotEqual(f1, f5)
def test_init_generator(self): def gen(): for x in [(1, 2), (4, 7)]: yield x f = Interval(interval_metadata=self.im, bounds=gen(), fuzzy=((True, False), (False, False)), metadata={'name': 'sagA', 'function': 'transport'}) self.assertTrue(f._interval_metadata is not None) self.assertListEqual(f.bounds, [(1, 2), (4, 7)]) self.assertListEqual(f.fuzzy, [(True, False), (False, False)]) self.assertDictEqual(f.metadata, {'name': 'sagA', 'function': 'transport'})
def test_set_delete_on_dropped(self): f = Interval(interval_metadata=self.im, bounds=[(1, 2)], fuzzy=[(True, False)], metadata={'name': 'sagA'}) f.drop() with self.assertRaises(RuntimeError): f.fuzzy = None with self.assertRaises(RuntimeError): f.bounds = [(1, 2)] with self.assertRaises(RuntimeError): f.metadata = {} with self.assertRaises(RuntimeError): del f.fuzzy with self.assertRaises(RuntimeError): del f.metadata
def test_sort(self): interval = Interval( self.im_2, [(1, 2), (3, 8)], metadata={'gene': 'sagA', 'bound': 0}) im = deepcopy(self.im_2) self.im_2.sort(False) # check sorting does not have other side effects self.assertEqual(im, self.im_2) self.assertEqual(self.im_2._intervals, [self.im_2_2, self.im_2_1, interval]) self.im_2.sort() self.assertEqual(im, self.im_2) self.assertEqual(self.im_2._intervals, [interval, self.im_2_1, self.im_2_2]) self.im_empty.sort() self.assertEqual(self.im_empty, IntervalMetadata(self.upper_bound))
def test_init_empty_metadata(self): for i in 0, 1: # test that no exception is raised Interval(interval_metadata=self.im, bounds=[(i, i)])
def test_init_empty(self): for i in 0, 1: with self.assertRaises(ValueError): Interval(interval_metadata=self.im, bounds=[(i, i)])