diff options
| author | mosimchah <mosimchah@gmail.com> | 2025-12-02 09:26:21 -0500 |
|---|---|---|
| committer | mosimchah <mosimchah@gmail.com> | 2025-12-02 09:26:21 -0500 |
| commit | 278dd9b39c5a3de6320e17d3dd1d10bf447bcc49 (patch) | |
| tree | 333c700c958401ad1ef3446d93eee54dac639cfa /tools/edit_monitor/edit_monitor_test.py | |
| parent | 9b9f43f3305e3304678676813d1fd5945a5f40bf (diff) | |
| parent | 00fcf469ba572bbce3f7c81fb346cccdbfa04219 (diff) | |
Merge branch 'lineage-23.1' of https://github.com/LineageOS/android_build into HEADw16.1
* 'lineage-23.1' of https://github.com/LineageOS/android_build: (415 commits)
Exclude perf-setup-sh from userdebug builds
Reapply "Drop legacy vboot support."
Revert "build: Enable super image build rules depending on single super block device"
Version bump to BP3A.250905.014 [core/build_id.mk]
Version bump to BP3A.250905.013 [core/build_id.mk]
Version bump to BP3A.250905.012 [core/build_id.mk]
Version bump to BP3A.250905.011 [core/build_id.mk]
Version bump to BP3A.250905.007.W1 [core/build_id.mk]
Version bump to BP3A.250905.005.X5 [core/build_id.mk]
Add apexd.mainline_patch_level_2 to PRODUCT_PACKAGES
Version bump to BP3A.250905.009 [core/build_id.mk]
Version bump to BP3A.250905.008 [core/build_id.mk]
Version bump to BP3A.250905.005.X4 [core/build_id.mk]
Version bump to BP3A.250905.005.Y1 [core/build_id.mk]
Version bump to BP3A.250905.007 [core/build_id.mk]
Version bump to BP3A.250905.005.X3 [core/build_id.mk]
Version bump to BP3A.250905.005.X2 [core/build_id.mk]
Version bump to BP3A.250905.005.X1 [core/build_id.mk]
Version bump to BP3A.250905.006 [core/build_id.mk]
Version bump to BP3A.250905.005 [core/build_id.mk]
...
Change-Id: I84161b0f013eb40002a433053b9383240274e9ea
Diffstat (limited to 'tools/edit_monitor/edit_monitor_test.py')
| -rw-r--r-- | tools/edit_monitor/edit_monitor_test.py | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/tools/edit_monitor/edit_monitor_test.py b/tools/edit_monitor/edit_monitor_test.py index deb73e724b..ce77284fb2 100644 --- a/tools/edit_monitor/edit_monitor_test.py +++ b/tools/edit_monitor/edit_monitor_test.py @@ -56,17 +56,19 @@ class EditMonitorTest(unittest.TestCase): def test_log_single_edit_event_success(self): # Create the .git file under the monitoring dir. self.root_monitoring_path.joinpath('.git').touch() + test_dir = self.root_monitoring_path.joinpath('test') + test_dir.mkdir() fake_cclient = FakeClearcutClient( log_output_file=self.log_event_dir.joinpath('logs.output') ) p = self._start_test_edit_monitor_process(fake_cclient) # Create and modify a file. - test_file = self.root_monitoring_path.joinpath('test.txt') + test_file = test_dir.joinpath('test.txt') with open(test_file, 'w') as f: f.write('something') # Move the file. - test_file_moved = self.root_monitoring_path.joinpath('new_test.txt') + test_file_moved = test_dir.joinpath('new_test.txt') test_file.rename(test_file_moved) # Delete the file. test_file_moved.unlink() @@ -79,27 +81,15 @@ class EditMonitorTest(unittest.TestCase): logged_events = self._get_logged_events() self.assertEqual(len(logged_events), 4) expected_create_event = edit_event_pb2.EditEvent.SingleEditEvent( - file_path=str( - self.root_monitoring_path.joinpath('test.txt').resolve() - ), edit_type=edit_event_pb2.EditEvent.CREATE, ) expected_modify_event = edit_event_pb2.EditEvent.SingleEditEvent( - file_path=str( - self.root_monitoring_path.joinpath('test.txt').resolve() - ), edit_type=edit_event_pb2.EditEvent.MODIFY, ) expected_move_event = edit_event_pb2.EditEvent.SingleEditEvent( - file_path=str( - self.root_monitoring_path.joinpath('test.txt').resolve() - ), edit_type=edit_event_pb2.EditEvent.MOVE, ) expected_delete_event = edit_event_pb2.EditEvent.SingleEditEvent( - file_path=str( - self.root_monitoring_path.joinpath('new_test.txt').resolve() - ), edit_type=edit_event_pb2.EditEvent.DELETE, ) self.assertEqual( @@ -127,10 +117,11 @@ class EditMonitorTest(unittest.TestCase): ).single_edit_event, ) - def test_log_aggregated_edit_event_success(self): # Create the .git file under the monitoring dir. self.root_monitoring_path.joinpath('.git').touch() + test_dir = self.root_monitoring_path.joinpath('test') + test_dir.mkdir() fake_cclient = FakeClearcutClient( log_output_file=self.log_event_dir.joinpath('logs.output') ) @@ -138,7 +129,7 @@ class EditMonitorTest(unittest.TestCase): # Create 6 test files for i in range(6): - test_file = self.root_monitoring_path.joinpath('test_' + str(i)) + test_file = test_dir.joinpath('test_' + str(i)) test_file.touch() # Give some time for the edit monitor to receive the edit event. @@ -163,9 +154,34 @@ class EditMonitorTest(unittest.TestCase): ).aggregated_edit_event, ) + def test_do_not_log_edit_event_under_out_dir(self): + # Create the .git file under the monitoring dir. + self.root_monitoring_path.joinpath('.git').touch() + fake_cclient = FakeClearcutClient( + log_output_file=self.log_event_dir.joinpath('logs.output') + ) + p = self._start_test_edit_monitor_process(fake_cclient) + + # Create out directory + self.root_monitoring_path.joinpath('out').mkdir() + # Create a file under out directory + test_file = self.root_monitoring_path.joinpath('out', 'test.txt') + with open(test_file, 'w') as f: + f.write('something') + # Give some time for the edit monitor to receive the edit event. + time.sleep(1) + # Stop the edit monitor and flush all events. + os.kill(p.pid, signal.SIGINT) + p.join() + + logged_events = self._get_logged_events() + self.assertEqual(len(logged_events), 0) + def test_do_not_log_edit_event_for_directory_change(self): # Create the .git file under the monitoring dir. self.root_monitoring_path.joinpath('.git').touch() + test_dir = self.root_monitoring_path.joinpath('test') + test_dir.mkdir() fake_cclient = FakeClearcutClient( log_output_file=self.log_event_dir.joinpath('logs.output') ) @@ -185,15 +201,17 @@ class EditMonitorTest(unittest.TestCase): def test_do_not_log_edit_event_for_hidden_file(self): # Create the .git file under the monitoring dir. self.root_monitoring_path.joinpath('.git').touch() + test_dir = self.root_monitoring_path.joinpath('test') + test_dir.mkdir() fake_cclient = FakeClearcutClient( log_output_file=self.log_event_dir.joinpath('logs.output') ) p = self._start_test_edit_monitor_process(fake_cclient) # Create a hidden file. - self.root_monitoring_path.joinpath('.test.txt').touch() + test_dir.joinpath('.test.txt').touch() # Create a hidden dir. - hidden_dir = self.root_monitoring_path.joinpath('.test') + hidden_dir = test_dir.joinpath('.test') hidden_dir.mkdir() hidden_dir.joinpath('test.txt').touch() # Give some time for the edit monitor to receive the edit event. @@ -206,15 +224,17 @@ class EditMonitorTest(unittest.TestCase): self.assertEqual(len(logged_events), 0) def test_do_not_log_edit_event_for_non_git_project_file(self): + test_dir = self.root_monitoring_path.joinpath('test') + test_dir.mkdir() fake_cclient = FakeClearcutClient( log_output_file=self.log_event_dir.joinpath('logs.output') ) p = self._start_test_edit_monitor_process(fake_cclient) # Create a file. - self.root_monitoring_path.joinpath('test.txt').touch() + test_dir.joinpath('test.txt').touch() # Create a file under a sub dir. - sub_dir = self.root_monitoring_path.joinpath('.test') + sub_dir = test_dir.joinpath('.test') sub_dir.mkdir() sub_dir.joinpath('test.txt').touch() # Give some time for the edit monitor to receive the edit event. @@ -229,6 +249,8 @@ class EditMonitorTest(unittest.TestCase): def test_log_edit_event_fail(self): # Create the .git file under the monitoring dir. self.root_monitoring_path.joinpath('.git').touch() + test_dir = self.root_monitoring_path.joinpath('test') + test_dir.mkdir() fake_cclient = FakeClearcutClient( log_output_file=self.log_event_dir.joinpath('logs.output'), raise_log_exception=True, @@ -236,7 +258,7 @@ class EditMonitorTest(unittest.TestCase): p = self._start_test_edit_monitor_process(fake_cclient) # Create a file. - self.root_monitoring_path.joinpath('test.txt').touch() + test_dir.joinpath('test.txt').touch() # Give some time for the edit monitor to receive the edit event. time.sleep(1) # Stop the edit monitor and flush all events. @@ -253,7 +275,14 @@ class EditMonitorTest(unittest.TestCase): # Start edit monitor in a subprocess. p = multiprocessing.Process( target=edit_monitor.start, - args=(str(self.root_monitoring_path.resolve()), False, 0.5, 5, cclient, sender), + args=( + str(self.root_monitoring_path.resolve()), + False, + 0.5, + 5, + cclient, + sender, + ), ) p.daemon = True p.start() |
