aboutsummaryrefslogtreecommitdiff
path: root/tools/edit_monitor/edit_monitor_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/edit_monitor/edit_monitor_test.py')
-rw-r--r--tools/edit_monitor/edit_monitor_test.py73
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()