Fix modified test to account for OS variances

This commit is contained in:
twangboy 2019-07-08 10:06:15 -06:00
parent 15ee4794c3
commit 02248dcd1a
No known key found for this signature in database
GPG key ID: 93FF3BDEB278C9EB

View file

@ -92,9 +92,21 @@ class IWatchdogBeaconTestCase(TestCase, LoaderModuleMockMixin):
ret = check_events(config)
self.assertEqual(len(ret), 1)
self.assertEqual(ret[0]['path'], path)
self.assertEqual(ret[0]['change'], 'modified')
modified = False
for event in ret:
# "modified" requires special handling
# A modification sometimes triggers 2 modified events depending on
# the OS and the python version
# When the "modified" event triggers on modify, it will have the
# path to the temp file (path), other modified events will contain
# the path minus "tmpfile" and will not match. That's how we'll
# distinguish the two
if event['change'] == 'modified':
if event['path'] == path:
modified = True
# Check results of the for loop to validate modified
self.assertTrue(modified)
def test_file_deleted(self):
path = os.path.join(self.tmpdir, 'tmpfile')