def test_set_segment_labels_overlap(self): segment_from_list = [] segment_from_list.append(segment.Segment(0, 1, "a")) segment_to_list = [] segment_to_list.append(segment.Segment(0.4, 1.5)) segment_to_list.append(segment.Segment(0.6, 1.5)) segment.set_segment_labels(segment_from_list, segment_to_list, overlap_ratio=0.5) assert (segment_to_list[0].label == "a" and segment_to_list[1].label == segment.CommonLabels.unknown.value)
def test_init(self): try: start_time = 1 end_time = 10 segment.Segment(start_time, end_time) except ParameterError: pytest.fail("Unexpected ParameterError")
def sc_list(self, n_files, file_list, label_list): sc_list = [] for i in range(n_files): sc = segment_container.SegmentContainer(file_list[i]) sc.segments.append(segment.Segment(0, 1, label_list[i])) sc_list.append(sc) return sc_list
def test_n_segments_w_label(self): sc = segment_container.SegmentContainer("fake_audio_path") n_segments = 5 for i in range(n_segments): sc.segments.append(segment.Segment(i * 1, (i + 1) * 1)) assert sc.n_segments_with_label( segment.CommonLabels.unknown.value) == n_segments
def test_n_active_segments(self): sc = segment_container.SegmentContainer("fake_audio_path") n_segments = 5 active_segment_ind = [2, 3] for i in range(n_segments): sc.segments.append(segment.Segment(i * 1, (i + 1) * 1)) if i in active_segment_ind: sc.segments[-1].activity = True assert sc.n_active_segments == len(active_segment_ind)
def test_n_active_segments_w_labels(self): sc = segment_container.SegmentContainer("fake_audio_path") n_segments = 5 active_segment_ind = [2, 3] for i in range(n_segments): sc.segments.append(segment.Segment(i * 1, (i + 1) * 1)) if i in active_segment_ind: sc.segments[-1].activity = True assert sc.n_active_segments_with_label( segment.CommonLabels.unknown.value) == len(active_segment_ind)
def test_set_segment_labels(self): segment_from_list = [] segment_from_list.append(segment.Segment(0, 1, "a")) segment_from_list.append(segment.Segment(1.2, 2, "b")) segment_to_list = [] segment_to_list.append(segment.Segment(0.2, 0.3)) segment_to_list.append(segment.Segment(0.6, 1.1)) segment_to_list.append(segment.Segment(1.7, 1.8)) segment_to_list.append(segment.Segment(2.5, 2.7)) segment.set_segment_labels(segment_from_list, segment_to_list, overlap_ratio=0.5) assert (segment_to_list[0].label == "a" and segment_to_list[1].label == "a" and segment_to_list[2].label == "b" and segment_to_list[3].label == segment.CommonLabels.unknown.value)
def test_time_order(self): with pytest.raises(ParameterError): start_time = 3 end_time = 1 segment.Segment(start_time, end_time)
def test_negative_start_time(self): with pytest.raises(ParameterError): start_time = -1 end_time = 10 segment.Segment(start_time, end_time)
def test_no_active_segments(self): sc = segment_container.SegmentContainer("fake_audio_path") n_segments = 5 for i in range(n_segments): sc.segments.append(segment.Segment(i * 1, (i + 1) * 1)) assert sc.n_active_segments == 0