def test_empty_month_range(self) -> None: """Tests the case when the month range is empty.""" src_root = config.get_abspath("workdir/stats") j: Dict[str, Any] = {} stats.handle_monthly_new(src_root, j, month_range=-1) monthly = j["monthly"] self.assertTrue(monthly)
def test_empty_month_range(self) -> None: """Tests the case when the month range is empty.""" ctx = test_context.make_test_context() ctx.set_time(test_context.make_test_time()) src_root = ctx.get_abspath("workdir/stats") j: Dict[str, Any] = {} stats.handle_monthly_new(ctx, src_root, j, month_range=-1) monthly = j["monthly"] self.assertTrue(monthly)
def test_happy(self) -> None: """Tests the happy path.""" src_root = config.get_abspath("workdir/stats") j: Dict[str, Any] = {} with unittest.mock.patch('datetime.date', MockDate): stats.handle_monthly_new(src_root, j) monthly = j["monthly"] self.assertEqual(len(monthly), 2) # 2019-05 start -> end self.assertEqual(monthly[0], ["2019-05", 3799]) # diff from last month end -> today self.assertEqual(monthly[1], ["2020-05", 51334])
def test_happy(self) -> None: """Tests the happy path.""" ctx = test_context.make_test_context() ctx.set_time(test_context.make_test_time()) src_root = ctx.get_abspath("workdir/stats") j: Dict[str, Any] = {} stats.handle_monthly_new(ctx, src_root, j) monthly = j["monthly"] self.assertEqual(len(monthly), 2) # 2019-05 start -> end self.assertEqual(monthly[0], ["2019-05", 3799]) # diff from last month end -> today self.assertEqual(monthly[1], ["2020-05", 51334])
def test_incomplete_last_month(self) -> None: """Tests the case when we have no data for the last, incomplete month.""" ctx = test_context.make_test_context() ctx.set_time(test_context.make_test_time()) src_root = ctx.get_abspath("workdir/stats") j: Dict[str, Any] = {} # This would be the data for the current state of the last, incomplete month. hide_path = ctx.get_abspath("workdir/stats/2020-05-10.count") file_system = test_context.TestFileSystem() file_system.set_hide_paths([hide_path]) ctx.set_file_system(file_system) stats.handle_monthly_new(ctx, src_root, j) monthly = j["monthly"] # 1st element: 2019-05 start -> end # No 2nd element, would be diff from last month end -> today self.assertEqual(len(monthly), 1) self.assertEqual(monthly[0], ["2019-05", 3799])
def test_incomplete_last_month(self) -> None: """Tests the case when we have no data for the last, incomplete month.""" src_root = config.get_abspath("workdir/stats") j: Dict[str, Any] = {} with unittest.mock.patch('datetime.date', MockDate): # This would be the data for the current state of the last, incomplete month. hide_path = config.get_abspath("workdir/stats/2020-05-10.count") real_exists = os.path.exists def mock_exists(path: str) -> bool: if path == hide_path: return False return real_exists(path) with unittest.mock.patch('os.path.exists', mock_exists): stats.handle_monthly_new(src_root, j) monthly = j["monthly"] # 1st element: 2019-05 start -> end # No 2nd element, would be diff from last month end -> today self.assertEqual(len(monthly), 1) self.assertEqual(monthly[0], ["2019-05", 3799])