def test_to_praat_overlapping_intervals(self): int1 = Interval(0.25, 0.35, 'a') int2 = Interval(0.3, 0.4, 'a') tier = IntervalTier('abc', 0.25, 1, [int1, int2]) with assert_raises(ValueError): tier.to_praat()
def test_str(self): int1 = Interval(0, 0.5, 'a') int2 = Interval(0.75, 1, 'c') tier = IntervalTier('abc', 0, 1, [int1, int2]) assert_equal( str(tier), '<IntervalTier "abc" from 0 to 1 seconds ' 'with 2 intervals>')
def test_repr(self): int1 = Interval(0, 0.5, 'a') int2 = Interval(0.75, 1, 'c') tier = IntervalTier('abc', 0, 1, [int1, int2]) assert_equal( repr(tier), "IntervalTier('abc', 0, 1, " "[Interval(0, 0.5, 'a'), " "Interval(0.75, 1, 'c')])")
def test_insert(self): int1 = Interval(0, 0.5, 'a') int2 = Interval(0.75, 1, 'c') tier = IntervalTier('abc', 0, 1, [int1, int2]) tier.insert(0.5, 0.75, 'b') assert_is(tier[0], int1) assert_is(tier[2], int2) assert_equal(tier[1].xmin, 0.5) assert_equal(tier[1].xmax, 0.75) assert_equal(tier[1].text, 'b')
def test_from_reader(self): stream = iter([0.5, 2.5, 'abc']) interval = Interval.from_reader(stream) assert_equal(interval.xmin, 0.5) assert_equal(interval.xmax, 2.5) assert_equal(interval.text, 'abc')
def test_where(self): int1 = Interval(0, 0.5, 'a') int2 = Interval(0.5, 0.6, 'b') int3 = Interval(0.75, 1, 'c') tier = IntervalTier('abc', 0, 1, [int1, int2, int3]) assert_is(tier.where(0), int1) assert_is(tier.where(0.25), int1) assert_is(tier.where(0.5), int2) assert_is(tier.where(0.55), int2) assert_is_none(tier.where(0.6)) assert_is_none(tier.where(0.65)) assert_is(tier.where(0.75), int3) assert_is(tier.where(0.8), int3) assert_is_none(tier.where(1))
def test_to_praat(self): interval = Interval(0.35, 0.5, 'a') tier = IntervalTier('abc', 0.25, 1, [interval]) expected = ('"IntervalTier" named "abc" \n' 'From 0.25 to 1 seconds with 3 intervals\n' ' 0.25 0.35 ' '"" \n' ' 0.35 0.5 ' '"a" \n' ' 0.5 1 ' '"" ') assert_equal(tier.to_praat(), expected)
def test_to_dict(self): interval = Interval(0.35, 0.5, 'a') tier = IntervalTier('abc', 0.25, 1, [interval]) assert_equal( tier.to_dict(), { 'xmin': 0.25, 'xmax': 1, 'name': 'abc', 'class': 'IntervalTier', 'intervals': [{ 'xmin': 0.35, 'xmax': 0.5, 'text': 'a' }] })
def test_to_praat_late_interval(self): interval = Interval(0.25, 1.5, 'a') tier = IntervalTier('abc', 0.25, 1, [interval]) with assert_raises(ValueError): tier.to_praat()
def test_where_out_of_bounds(self): interval = Interval(0.35, 0.5, 'a') tier = IntervalTier('abc', 0.25, 1, [interval]) assert_is_none(tier.where(0.1)) assert_is_none(tier.where(1.5))
def test_init_unsortable(self): with assert_raises(TypeError): Tier('abc', 0, 1, [Interval(0, 1, 'abc'), Point(0.5, 'abc')])
def test_intervals_are_not_equal(self): interval = Interval(0.5, 2.5, 'abc') assert_not_equal(self.int1, interval)
def setup_class(cls): cls.int1 = Interval(0.5, 2.5, 'abc') cls.int2 = Interval(0.65, 2.5, 'abc')