Exemplo n.º 1
0
 def test_get_all_task_ids_with_duration(self):
     df = read_log_sample("tasks_multiple_nested")
     expected = {
         "task1": timedelta(hours=2),
         "task2": timedelta(minutes=1),
         "task3": timedelta(hours=1, minutes=30),
     }
     actual = get_all_task_ids_with_duration(df)
     self.assertEqual(actual, expected)
Exemplo n.º 2
0
    def test_extraction(self):
        df = read_log_sample("session_simple")

        expected = DataFrame({
            "date": [date(2020, 1, 1), date(2020, 1, 1)],
            "time": [time(0, 0, 0), time(1, 0, 0)],
        })
        actual = extract_date_and_time(df)

        pd.testing.assert_frame_equal(actual, expected)
Exemplo n.º 3
0
    def test_extract_intervals_invalid_start_missing(self):
        mock_logger = Mock(logging.Logger)
        df = read_log_sample("tasks_start_missing")

        actual = extract_intervals(df, logger=mock_logger)
        expected = DataFrame(columns=["date", "start", "stop", "interval"])

        pd.testing.assert_frame_equal(actual, expected)
        mock_logger.error.assert_called_once_with(
            "No start entry found. Skip entry.")
Exemplo n.º 4
0
 def test_calc_task_durations_open_interval(self):
     df = read_log_sample("tasks_open_interval")
     expected = DataFrame(
         {
             wc.COL_TASK_IDENTIFIER: ["foo"],
             "time": [timedelta(hours=1)]
         },
         index=[1])
     actual = _calc_single_task_duration(
         df, keep_cols=[wc.COL_TASK_IDENTIFIER, "time"])
     pd.testing.assert_frame_equal(actual, expected)
Exemplo n.º 5
0
 def calc_task_durations_multiple_ordered(self):
     df = read_log_sample("tasks_multiple_ordered")
     expected = DataFrame(
         {
             wc.COL_TASK_IDENTIFIER: ["bar", "foo"],
             "time": [timedelta(minutes=30),
                      timedelta(hours=1)],
         },
         index=[3, 1],
     )
     actual = calc_task_durations(df)
     pd.testing.assert_frame_equal(actual, expected)
Exemplo n.º 6
0
    def test_extract_intervals_valid(self):
        mock_logger = Mock(logging.Logger)
        df = read_log_sample("tasks_simple_ordered")

        actual = extract_intervals(df, logger=mock_logger)
        expected = DataFrame({
            "date": [date(2020, 1, 1)],
            "start": [datetime(2020, 1, 1, 0, tzinfo=timezone.utc)],
            "stop": [datetime(2020, 1, 1, 1, tzinfo=timezone.utc)],
            "interval": [timedelta(hours=1)],
        })

        pd.testing.assert_frame_equal(actual, expected)
        mock_logger.error.assert_not_called()
Exemplo n.º 7
0
    def test_extract_intervals_invalid_unknown_type(self):
        mock_logger = Mock(logging.Logger)
        df = read_log_sample("tasks_invalid_type")

        actual = extract_intervals(df, logger=mock_logger)
        expected = DataFrame({
            "date": [date(2020, 1, 1)],
            "start": [datetime(2020, 1, 1, 0, tzinfo=timezone.utc)],
            "stop": [datetime(2020, 1, 1, 1, tzinfo=timezone.utc)],
            "interval": [timedelta(hours=1)],
        })

        pd.testing.assert_frame_equal(actual, expected)
        mock_logger.error.assert_called_once_with(
            "Found unknown type 'unknown'. Skip entry.")
Exemplo n.º 8
0
    def test_extract_intervals_invalid_stop_missing(self):
        mock_logger = Mock(logging.Logger)
        df = read_log_sample("tasks_open_interval")

        actual = extract_intervals(df, logger=mock_logger)
        expected = DataFrame({
            "date": [date(2020, 1, 1)],
            "start": [datetime(2020, 1, 1, 0, tzinfo=timezone.utc)],
            "stop": [datetime(2020, 1, 1, 1, tzinfo=timezone.utc)],
            "interval": [timedelta(hours=1)],
        })

        pd.testing.assert_frame_equal(actual, expected)
        mock_logger.error.assert_called_once_with(
            "Start entry at 2020-01-01 01:30:00+00:00 has no stop entry. Skip entry."
        )
Exemplo n.º 9
0
 def test_calc_task_durations_multiple_unordered(self):
     """
     Test if implementation works if the log entries are in the wrong
     order. In this case a stop entry is listed before a start entry
     although the order of the logged time is fine.
     """
     df = read_log_sample("tasks_multiple_nested_unordered")
     expected = DataFrame(
         {
             wc.COL_TASK_IDENTIFIER: ["task1", "task2"],
             "time": [timedelta(hours=2),
                      timedelta(minutes=1)],
         },
         index=pd.MultiIndex.from_tuples(
             [("task1", 1), ("task2", 0)],
             names=[wc.COL_TASK_IDENTIFIER, None],
         ),
     )
     actual = calc_task_durations(df)
     pd.testing.assert_frame_equal(actual, expected)
Exemplo n.º 10
0
 def test_calc_task_durations_multiple_nested(self):
     """
     Test if the implementation works if tasks are nested.
     """
     df = read_log_sample("tasks_multiple_nested")
     expected = DataFrame(
         {
             wc.COL_TASK_IDENTIFIER: ["task1", "task2", "task3"],
             "time": [
                 timedelta(hours=2),
                 timedelta(minutes=1),
                 timedelta(hours=1, minutes=30),
             ],
         },
         index=pd.MultiIndex.from_tuples(
             [("task1", 4), ("task2", 3), ("task3", 5)],
             names=[wc.COL_TASK_IDENTIFIER, None],
         ),
     )
     actual = calc_task_durations(df)
     pd.testing.assert_frame_equal(actual, expected)
Exemplo n.º 11
0
    def xtest_extraction(self):
        df = read_log_sample("session_simple")

        expected = DataFrame({
            "date": [date(2020, 1, 1), date(2020, 1, 1)],
            "time": [
                time(hour=0, tzinfo=timezone.utc),
                time(hour=1, tzinfo=timezone.utc),
            ],
            wc.COL_LOG_DATETIME_UTC: [
                datetime(2020, 1, 1, tzinfo=timezone.utc),
                datetime(2020, 1, 1, tzinfo=timezone.utc),
            ],
            wc.COL_COMMIT_DATETIME_UTC: [
                datetime(2020, 1, 1, tzinfo=timezone.utc),
                datetime(2020, 1, 1, tzinfo=timezone.utc),
            ],
        })
        actual = extract_date_and_time(df)

        pd.testing.assert_frame_equal(actual, expected)
Exemplo n.º 12
0
    def test_active_session(self):
        df = read_log_sample("session_simple_open")
        actual = is_active_session(df)

        self.assertTrue(actual)
Exemplo n.º 13
0
    def test_inactive_session(self):
        df = read_log_sample("session_simple")
        actual = is_active_session(df)

        self.assertFalse(actual)
Exemplo n.º 14
0
 def test_get_active_task_ids_multiple(self):
     df = read_log_sample("tasks_multiple_started")
     expected = ["task1", "task3"]
     actual = get_active_task_ids(df)
     self.assertEqual(actual, expected)
Exemplo n.º 15
0
 def test_get_active_task_ids_single(self):
     df = read_log_sample("tasks_simple_active")
     expected = ["task1"]
     actual = get_active_task_ids(df)
     self.assertEqual(actual, expected)