Commits

Christopher Nilsson committed 2ddf934

moved test directory to be a sibling of dirwatch, instead of subdir

Comments (0)

Files changed (6)

 include README
 include *.txt
 recursive-include docs *.txt
-recursive-include dirwatch *.py *.txt
+recursive-include dirwatch *.py 
+recursive-include test *.py

dirwatch/test/__init__.py

Empty file removed.

dirwatch/test/test_dirwatch.py

-import unittest
-import dirwatch
-import dirwatch.eventtype
-import os
-import os.path
-import time
-import tempfile
-
-def get_test_dir():
-    return tempfile.gettempdir()
-def get_test_filename(tmpdir=None):
-    # Explicitly want mktemp -- since we don't want the file to be created 
-    # for us ahead of time.  
-    return tempfile.mktemp(dir=tmpdir)
-
-class TestDirWatch(unittest.TestCase):
-    def setUp(self):
-        self.path_events = {}
-        self.dw = dirwatch.create_dirwatcher()
-        self.dw.events.subscribe(dirwatch.eventtype.EV_FILE_CREATED, self.on_dir_event)
-        self.testdir = get_test_dir()
-        self.testfilename = get_test_filename(self.testdir)
-        self.cleanup = []
-        
-    def tearDown(self):
-        self.dw.events.unsubscribe(dirwatch.eventtype.EV_FILE_CREATED, self.on_dir_event)
-        self.path_events = None
-        self.dw = None
-        if os.path.exists(self.testfilename):
-            os.remove(self.testfilename)
-        for path in self.cleanup:
-            if os.path.exists(path):
-                os.remove(path)
-        
-    def on_dir_event(self, event):
-        path = event.path
-        if path:
-            if path not in self.path_events:
-                self.path_events[path] = []
-            self.path_events[path].append(event) 
-            #print "%s [%s] %s" % (time.ctime(event.timestamp), event.event_type, event.path)           
-        
-    def test_on_create(self):
-        """ Check we see some events on creating a test file.         
-        """                
-        self.dw.add_watch(self.testdir)
-        
-        self.dw.start_monitor()
-        try:
-            self.assertNotIn(self.testfilename, self.path_events, "Test file '%s' already in event list?" % self.testfilename)
-            
-            with open(self.testfilename, "w+") as testfile:
-                testfile.write("testing. 1, 2, 3.\n")
-                testfile.close()
-            time.sleep(0.04)
-            self.assertIn(self.testfilename, self.path_events, "Test file '%s' NOT in event list." % self.testfilename)
-        finally:
-            self.dw.stop_monitor()
-            
-    def test_multiple_creates(self):
-        """ Check we see the events for ALL our files.         
-        """
-        self.dw.add_watch(self.testdir)
-        self.dw.start_monitor()
-        try:
-            num_of_paths = 1000            
-            for idx in range(num_of_paths):
-                with open(self.testfilename + "_" + str(idx), "w+") as testfile:
-                    testfile.write("test")
-                    testfile.close()
-                    self.cleanup.append(self.testfilename + "_" + str(idx))
-                time.sleep(0.02) # yield cpu in between file drops...
-        finally:
-            self.dw.stop_monitor()
-        self.assertEquals(num_of_paths, len(self.path_events.keys()))
-        
-    def test_copyfile_to_watch_dir(self):
-        """ Check we notice when a file is copied into our watched directory.         
-        """
-        self.dw.add_watch(self.testdir)
-        self.dw.start_monitor()
-        outfilename = get_test_filename()
-        try:
-            with open(__file__, "r") as srcf, open(outfilename, "w") as outf:
-                for line in srcf:
-                    outf.write(line)
-            self.cleanup.append(outfilename)
-        finally:
-            self.dw.stop_monitor()
-        
-        self.assertIn(outfilename, self.path_events, "Test file '{0}' not seen".format(outfilename))
-        
-    def test_movefile_to_watch_dir(self):
-        """ Check we notice when a file is moved into our watched directory (usually no modify involved).         
-        """
-        self.dw.add_watch(self.testdir)
-        self.dw.start_monitor()
-        outfilename = get_test_filename()
-        srcfilename = os.path.join(os.getcwd(), "testsrcfile")
-        try:
-            with open(srcfilename, "w+") as srcfile:
-                srcfile.write("testing...\n")
-            try:
-                os.rename(srcfilename, outfilename)
-            except:
-                self.cleanup.append(srcfilename)
-            else:
-                self.cleanup.append(outfilename)
-        finally:
-            self.dw.stop_monitor()
-        
-        self.assertIn(outfilename, self.path_events, "Test file '{0}' not seen".format(outfilename))    
-        
-            
-
-if __name__ == "__main__":
-    unittest.main(verbosity=2)
-    
     author='Chris Nilsson',
     author_email='christopher@otherchirps.net',
     packages=['dirwatch', 'dirwatch.test'],
-    url='http://bitbucket.org/otherchirps/dirwatch',
+    url='https://bitbucket.org/otherchirps/dirwatch',
+    download_url='https://bitbucket.org/otherchirps/dirwatch',
     license='LICENSE.txt',
     description='Listens for file-system events in nominated directories.',
     long_description=open('README').read(),

test/__init__.py

Empty file added.

test/test_dirwatch.py

+import unittest
+import dirwatch
+import dirwatch.eventtype
+import os
+import os.path
+import time
+import tempfile
+
+def get_test_dir():
+    return tempfile.gettempdir()
+def get_test_filename(tmpdir=None):
+    # Explicitly want mktemp -- since we don't want the file to be created 
+    # for us ahead of time.  
+    return tempfile.mktemp(dir=tmpdir)
+
+class TestDirWatch(unittest.TestCase):
+    def setUp(self):
+        self.path_events = {}
+        self.dw = dirwatch.create_dirwatcher()
+        self.dw.events.subscribe(dirwatch.eventtype.EV_FILE_CREATED, self.on_dir_event)
+        self.testdir = get_test_dir()
+        self.testfilename = get_test_filename(self.testdir)
+        self.cleanup = []
+        
+    def tearDown(self):
+        self.dw.events.unsubscribe(dirwatch.eventtype.EV_FILE_CREATED, self.on_dir_event)
+        self.path_events = None
+        self.dw = None
+        if os.path.exists(self.testfilename):
+            os.remove(self.testfilename)
+        for path in self.cleanup:
+            if os.path.exists(path):
+                os.remove(path)
+        
+    def on_dir_event(self, event):
+        path = event.path
+        if path:
+            if path not in self.path_events:
+                self.path_events[path] = []
+            self.path_events[path].append(event) 
+            #print "%s [%s] %s" % (time.ctime(event.timestamp), event.event_type, event.path)           
+        
+    def test_on_create(self):
+        """ Check we see some events on creating a test file.         
+        """                
+        self.dw.add_watch(self.testdir)
+        
+        self.dw.start_monitor()
+        try:
+            self.assertNotIn(self.testfilename, self.path_events, "Test file '%s' already in event list?" % self.testfilename)
+            
+            with open(self.testfilename, "w+") as testfile:
+                testfile.write("testing. 1, 2, 3.\n")
+                testfile.close()
+            time.sleep(0.04)
+            self.assertIn(self.testfilename, self.path_events, "Test file '%s' NOT in event list." % self.testfilename)
+        finally:
+            self.dw.stop_monitor()
+            
+    def test_multiple_creates(self):
+        """ Check we see the events for ALL our files.         
+        """
+        self.dw.add_watch(self.testdir)
+        self.dw.start_monitor()
+        try:
+            num_of_paths = 1000            
+            for idx in range(num_of_paths):
+                with open(self.testfilename + "_" + str(idx), "w+") as testfile:
+                    testfile.write("test")
+                    testfile.close()
+                    self.cleanup.append(self.testfilename + "_" + str(idx))
+                time.sleep(0.02) # yield cpu in between file drops...
+        finally:
+            self.dw.stop_monitor()
+        self.assertEquals(num_of_paths, len(self.path_events.keys()))
+        
+    def test_copyfile_to_watch_dir(self):
+        """ Check we notice when a file is copied into our watched directory.         
+        """
+        self.dw.add_watch(self.testdir)
+        self.dw.start_monitor()
+        outfilename = get_test_filename()
+        try:
+            with open(__file__, "r") as srcf, open(outfilename, "w") as outf:
+                for line in srcf:
+                    outf.write(line)
+            self.cleanup.append(outfilename)
+        finally:
+            self.dw.stop_monitor()
+        
+        self.assertIn(outfilename, self.path_events, "Test file '{0}' not seen".format(outfilename))
+        
+    def test_movefile_to_watch_dir(self):
+        """ Check we notice when a file is moved into our watched directory (usually no modify involved).         
+        """
+        self.dw.add_watch(self.testdir)
+        self.dw.start_monitor()
+        outfilename = get_test_filename()
+        srcfilename = os.path.join(os.getcwd(), "testsrcfile")
+        try:
+            with open(srcfilename, "w+") as srcfile:
+                srcfile.write("testing...\n")
+            try:
+                os.rename(srcfilename, outfilename)
+            except:
+                self.cleanup.append(srcfilename)
+            else:
+                self.cleanup.append(outfilename)
+        finally:
+            self.dw.stop_monitor()
+        
+        self.assertIn(outfilename, self.path_events, "Test file '{0}' not seen".format(outfilename))    
+        
+            
+
+if __name__ == "__main__":
+    unittest.main(verbosity=2)
+