diff --git a/tests/test_tracer.py b/tests/test_tracer.py index 84e27c8..421b119 100644 --- a/tests/test_tracer.py +++ b/tests/test_tracer.py @@ -19,17 +19,18 @@ class TestRules(unittest.TestCase): def setUp(self): Applications._apps = ApplicationsCollection() self.tracer = Tracer(PackageManagerMock(), Rules, Applications, memory=dump_memory_mock) - self.tracer.timestamp = 5555 # Sure, it should be a UNIX timestamp value Applications._append_application({"name": "kernel", "ignore": True}) Application.processes_factory = ProcessesMock @patch('tracer.resources.applications.System.init_system', return_value="dummy") - def test_trace_affected(self, init_system): + @patch('tracer.resources.applications.System.boot_time', return_value=5555) + def test_trace_affected(self, boot_time, init_system): affected = self.tracer.trace_affected() self.assertSetEqual(set(affected), set([Applications.find("baz"), Applications.find("qux")])) self.assertIsInstance(affected, ApplicationsCollection) - def test_trace_application(self): + @patch('tracer.resources.applications.System.boot_time', return_value=5555) + def test_trace_application(self, boot_time): affected = self.tracer.trace_application(Applications.find("baz"), AffectedProcessMock) self.assertIsInstance(affected, AffectedProcessesCollection) self.assertEqual(len(affected), 1) diff --git a/tracer/resources/args_parser.py b/tracer/resources/args_parser.py index 4eef578..243bfbb 100644 --- a/tracer/resources/args_parser.py +++ b/tracer/resources/args_parser.py @@ -58,6 +58,7 @@ parser.add_argument('-t', '--timestamp', nargs=1, default=[None], + type=float, dest='timestamp', help='since when the updates should be' ) diff --git a/tracer/resources/tracer.py b/tracer/resources/tracer.py index c2c19df..5d0d3e8 100644 --- a/tracer/resources/tracer.py +++ b/tracer/resources/tracer.py @@ -79,11 +79,19 @@ def _modified_packages(self): if self.specified_packages and self.now: return PackagesCollection(self.specified_packages) - timestamp = self.timestamp if self.timestamp else System.boot_time() + timestamp = self._timestamp() packages = self._PACKAGE_MANAGER.packages_newer_than(timestamp) packages = packages.intersection(self.specified_packages) return packages + def _timestamp(self): + boot = System.boot_time() + if not self.timestamp: + return boot + if self.timestamp < boot: + return boot + return self.timestamp + def trace_affected(self, user=None): """ Returns collection of applications which uses some files that have been modified