diff --git a/.coverage b/.coverage index ac029bf..5338883 100644 --- a/.coverage +++ b/.coverage @@ -1 +1 @@ -!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/dustin/development/python/pyinotify/inotify/test_support.py":[1,2,3,4,5,7,9,11,13,14,16,17,19,21,22],"/home/dustin/development/python/pyinotify/inotify/adapters.py":[1,2,3,4,5,6,8,10,11,15,16,20,22,23,25,26,27,28,31,32,35,36,39,40,41,42,43,44,46,47,49,51,53,56,59,60,61,63,65,66,67,69,70,72,73,75,76,78,84,85,88,89,91,92,93,95,97,98,99,100,101,102,104,105,107,110,112,115,117,118,121,123,124,126,132,134,135,136,138,139,141,142,145,148,150,152,153,154,161,162,163,165,170,171,172,176,177,191,194,195,196,197,199,200,201,202,204,208,209,210,216,217,219,221,230,231,232,234,235,238,239,242,245,247,250,252,253,256,259,261,264,265,267,268,269,271,273,275,276,278,280,281,282,283,285,287,288,289,292,294,295,298,299,301,302,303,305,307,308,310,312,313,314,315,317,319,327,328],"/home/dustin/development/python/pyinotify/inotify/library.py":[8,1,2,4,5],"/home/dustin/development/python/pyinotify/inotify/calls.py":[1,2,4,6,8,11,12,18,25,32,33,37,39,40,41,43,45,46,47,49,51,52,53,55,56],"/home/dustin/development/python/pyinotify/inotify/__init__.py":[1],"/home/dustin/development/python/pyinotify/inotify/constants.py":[3,4,8,9,10,11,12,13,14,15,16,17,18,19,23,24,30,34,35,36,40,41,42,43,44,46,47,48,52,53,54,55,56,57,58,59,60,61,62,63,67,68,69,73,74,75,76,77]}} \ No newline at end of file +!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/dustin/development/python/pyinotify/inotify/library.py":[8,1,2,4,5],"/home/eohm/github/Elias481/PyInotify/inotify/test_support.py":[1,2,3,4,5,7,9,11,13,14,16,17,19,21,22],"/home/eohm/github/Elias481/PyInotify/inotify/calls.py":[1,2,4,6,8,11,12,13,14,16,18,25,32,33,34,35,37,39,40,41,43,45,46,47,49,51,52,53,55,56],"/home/dustin/development/python/pyinotify/inotify/constants.py":[3,4,8,9,10,11,12,13,14,15,16,17,18,19,23,24,30,34,35,36,40,41,42,43,44,46,47,48,52,53,54,55,56,57,58,59,60,61,62,63,67,68,69,73,74,75,76,77],"/home/dustin/development/python/pyinotify/inotify/__init__.py":[1],"/home/eohm/github/Elias481/PyInotify/inotify/adapters.py":[1,2,3,4,5,6,8,10,11,15,16,20,25,27,28,30,31,32,33,36,37,40,41,44,45,50,51,52,53,54,55,57,58,60,61,63,65,68,71,72,73,75,77,78,79,81,82,89,90,91,93,95,96,98,99,101,103,109,110,113,114,116,118,120,121,123,124,126,128,129,130,131,132,133,135,136,138,141,143,146,147,150,152,153,155,161,163,164,165,167,168,169,171,172,175,178,180,182,183,184,185,187,188,189,192,193,201,203,204,205,209,210,224,227,228,230,231,232,234,235,236,240,243,245,246,247,248,250,253,258,259,260,266,267,269,271,280,281,282,284,285,288,289,292,293,295,297,300,302,303,306,309,310,317,318,320,322,324,326,331,332,334,335,336,338,340,342,343,345,347,348,349,350,352,354,355,356,359,361,362,365,366,368,369,370,372,374,375,377,379,380,381,382,384,386,394,395],"/home/eohm/github/Elias481/PyInotify/inotify/constants.py":[3,4,8,9,10,11,12,13,14,15,16,17,18,19,23,24,30,34,35,36,40,41,42,43,44,46,47,48,52,53,54,55,56,57,58,59,60,61,62,63,67,68,69,73,74,75,76,77],"/home/dustin/development/python/pyinotify/inotify/adapters.py":[1,2,3,4,5,6,8,10,11,15,16,20,22,23,25,26,27,28,31,32,35,36,39,40,41,42,43,44,46,47,49,51,53,56,59,60,61,63,65,66,67,69,70,72,73,75,76,78,84,85,88,89,91,92,93,95,97,98,99,100,101,102,104,105,107,110,112,115,117,118,121,123,124,126,132,134,135,136,138,139,141,142,145,148,150,152,153,154,161,162,163,165,170,171,172,176,177,191,194,195,196,197,199,200,201,202,204,208,209,210,216,217,219,221,230,231,232,234,235,238,239,242,245,247,250,252,253,256,259,261,264,265,267,268,269,271,273,275,276,278,280,281,282,283,285,287,288,289,292,294,295,298,299,301,302,303,305,307,308,310,312,313,314,315,317,319,327,328],"/home/dustin/development/python/pyinotify/inotify/calls.py":[1,2,4,6,8,11,12,18,25,32,33,37,39,40,41,43,45,46,47,49,51,52,53,55,56],"/home/eohm/github/Elias481/PyInotify/inotify/library.py":[1,2,4,5,8],"/home/eohm/github/Elias481/PyInotify/inotify/__init__.py":[1],"/home/dustin/development/python/pyinotify/inotify/test_support.py":[1,2,3,4,5,7,9,11,13,14,16,17,19,21,22]}} \ No newline at end of file diff --git a/tests/test_inotify.py b/tests/test_inotify.py index 0f87524..e7bd0fe 100644 --- a/tests/test_inotify.py +++ b/tests/test_inotify.py @@ -2,6 +2,7 @@ import os import unittest +import shutil import inotify.constants import inotify.adapters @@ -349,6 +350,79 @@ def test__automatic_new_watches_on_existing_paths(self): self.assertEquals(events, expected) + def test__readd_deleted_folder(self): + #test for https://github.com/dsoprea/PyInotify/issues/51 + #doing no checks the directory-discovery events as current master does + #not generate events that should really be expected in this case + #avoid having to adjust this - also not implement chcking for expected + #wd assignment now.. + #just check for no exception, file creation events and expected watches + #at the end. emulate slow succession of filesystem actions... (because + #of another unfixed bug and because this is needed to reproduces issue) + with inotify.test_support.temp_path() as path: + path1 = os.path.join(path, 'folder') + file1 = os.path.join(path1, 'file1') + file2 = os.path.join(path1, 'file2') + + i = inotify.adapters.InotifyTree(path) + os.mkdir(path1) + events = self.__read_all_events(i) + with open(file1, 'w'): + pass + with open(file2, 'w'): + pass + events = self.__read_all_events(i) + + expected = [ + (inotify.adapters._INOTIFY_EVENT(wd=2, mask=256, cookie=0, len=16), ['IN_CREATE'], path1, 'file1'), + (inotify.adapters._INOTIFY_EVENT(wd=2, mask=32, cookie=0, len=16), ['IN_OPEN'], path1, 'file1'), + (inotify.adapters._INOTIFY_EVENT(wd=2, mask=8, cookie=0, len=16), ['IN_CLOSE_WRITE'], path1, 'file1'), + (inotify.adapters._INOTIFY_EVENT(wd=2, mask=256, cookie=0, len=16), ['IN_CREATE'], path1, 'file2'), + (inotify.adapters._INOTIFY_EVENT(wd=2, mask=32, cookie=0, len=16), ['IN_OPEN'], path1, 'file2'), + (inotify.adapters._INOTIFY_EVENT(wd=2, mask=8, cookie=0, len=16), ['IN_CLOSE_WRITE'], path1, 'file2'), + ] + self.assertEquals(events, expected) + + shutil.rmtree(path1) + events = self.__read_all_events(i) + + #could do the following asserts here to prove the the assumption of amigian74 in + #his 5th point in issue 51 ("everything until now works fine") false, but that is + #not target of this test, also it is not his reposibility to verify this... + #so to get same issue he describes it's just a comment... + #self.assertEquals(len(i._i._Inotify__watches), 1) + #self.assertEquals(len(i._i._Inotify__watches_r), 1) + #self.assertNotIn(path1, i._i._Inotify__watches) + + os.mkdir(path1) + events = self.__read_all_events(i) + with open(file1, 'w'): + pass + with open(file2, 'w'): + pass + events = self.__read_all_events(i) + + watches = i._i._Inotify__watches + watches_reverse = i._i._Inotify__watches_r + + watches_expect = sorted((path,path1)) + watches_reg_names = sorted(watches.keys()) + watches_reg_check = dict((value, key) for key, value in watches.items()) + + self.assertEquals(watches_expect, watches_reg_names) + self.assertEquals(watches_reg_check, watches_reverse) + + wd = watches[path1] + expected = [ + (inotify.adapters._INOTIFY_EVENT(wd=wd, mask=256, cookie=0, len=16), ['IN_CREATE'], path1, 'file1'), + (inotify.adapters._INOTIFY_EVENT(wd=wd, mask=32, cookie=0, len=16), ['IN_OPEN'], path1, 'file1'), + (inotify.adapters._INOTIFY_EVENT(wd=wd, mask=8, cookie=0, len=16), ['IN_CLOSE_WRITE'], path1, 'file1'), + (inotify.adapters._INOTIFY_EVENT(wd=wd, mask=256, cookie=0, len=16), ['IN_CREATE'], path1, 'file2'), + (inotify.adapters._INOTIFY_EVENT(wd=wd, mask=32, cookie=0, len=16), ['IN_OPEN'], path1, 'file2'), + (inotify.adapters._INOTIFY_EVENT(wd=wd, mask=8, cookie=0, len=16), ['IN_CLOSE_WRITE'], path1, 'file2'), + ] + self.assertEquals(events, expected) + class TestInotifyTrees(unittest.TestCase): def __init__(self, *args, **kwargs):