def test_joint_update_lower_kgl(self): update_settings(n_keep=400, n_keep_logs=300, db_path=self.db_path) db = connect(self.db_path) with closing(db.cursor()) as cursor: cursor.execute("SELECT * FROM settings WHERE pk = 0") results = cursor.fetchall()[0] with self.subTest("n_keep updated"): self.assertEqual(results['n_keep'], 400) with self.subTest("n_keep_logs updated"): self.assertEqual(results['n_keep_logs'], 300)
def test_decrease_logs(self): update_settings(n_keep_logs=42, db_path=self.db_path) db = connect(self.db_path) with closing(db.cursor()) as cursor: cursor.execute("SELECT * FROM settings WHERE pk = 0") results = cursor.fetchall()[0] with self.subTest("n_keep not updated"): self.assertEqual(results['n_keep'], DEFAULT_KEEP) with self.subTest("n_keep_logs updated"): self.assertEqual(results['n_keep_logs'], 42)
def test_auto_delete(self): update_settings(n_keep=5, db_path=self.db_path) for i in range(7): system = sample_system_object() recorder = HistoryRecorder(system=system, est_path=f"{i}", db_path=self.db_path) with recorder: print(f"Run {i}") db = connect(self.db_path) with closing(db.cursor()) as cursor: cursor.execute("SELECT * FROM history") results = cursor.fetchall() with self.subTest("Ensure correct number retained"): self.assertEqual(len(results), 5) with self.subTest("Ensure correct entries retained"): actual_names = {result['file'] for result in results} expected_names = {f"{i}" for i in range(2, 7)} self.assertSetEqual(actual_names, expected_names) db.close()
def settings(args: Dict[str, Any], unknown: List[str]) -> None: if len(unknown) > 0: print("error: unrecognized arguments: ", str.join(", ", unknown)) sys.exit(-1) update_settings(n_keep=args['keep'], n_keep_logs=args['keep_logs'])