def test_double_nesting(): sut = Timeline('test_double_nest') with use_clock_mock() as clock_mock: # 1 - root # 2 ... 4.5 nested_1 # 3.1 ... 4.1 double_nested # 5 end root clock_mock.now.return_value = 1.0 sut.start() clock_mock.now.return_value = 2.0 sut.begin_nested_interval('nested_1') clock_mock.now.return_value = 3.1 sut.begin_nested_interval('double_nested') clock_mock.now.return_value = 4.1 sut.end_nested_interval() clock_mock.now.return_value = 4.5 sut.end_nested_interval() clock_mock.now.return_value = 5 sut.stop() sut.to_console() assert len(sut.root.intervals) == 1 assert sut.root.duration() == 4 nested_1 = sut.root.intervals[0] assert nested_1.duration() == 2.5 double_nested = nested_1.intervals[0] assert double_nested.duration() == pytest.approx(1) print_duration(sut)
def test_complex_nesting(): sut = Timeline('complex') # 1 - root # 2 ... 4.5 nested_1 # 3.1 ... 4.1 double_nested # 5 end root sut.start() sut.begin_nested_interval('nested_1') sut.begin_nested_interval('a') sut.end_nested_interval() sut.begin_nested_interval('b') sut.end_nested_interval() sut.begin_nested_interval('c') sut.end_nested_interval() sut.end_nested_interval() sut.begin_nested_interval('1') sut.end_nested_interval() sut.begin_nested_interval('2') sut.begin_nested_interval('2.1') sut.end_nested_interval() sut.begin_nested_interval('2.2') sut.begin_nested_interval('2.2.1') sut.end_nested_interval() sut.end_nested_interval() sut.end_nested_interval() sut.begin_nested_interval('3') sut.end_nested_interval() sut.stop() sut.to_console()
def test_marker_inside_interval(): sut = Timeline('test 1') with use_clock_mock() as clock_mock: clock_mock.now.return_value = 1.0 sut.start() clock_mock.now.return_value = 2.0 sut.begin_nested_interval('nested') clock_mock.now.return_value = 3.0 sut.mark_event('event_1') clock_mock.now.return_value = 4.0 sut.end_nested_interval() sut.mark_event('outer') clock_mock.now.return_value = 5.0 sut.stop() sut.to_console() assert len(sut.root.events) == 1 assert sut.root.events[0].name == 'outer' assert sut.root.events[0].timestamp == 4.0 assert sut.root.intervals[0].events[0].timestamp == 3.0 assert sut.root.intervals[0].events[0].name == 'event_1'