示例#1
0
    def test_Touch(self):
        """Testing Touch() function"""
        try:
            print("Touch non-existent file")
            self.assertFalse(Tf.TouchFile("touchFile", False))
            self.assertFalse(os.path.isfile("touchFile"))

            print("Touch non-existent file with create flag")
            self.assertTrue(Tf.TouchFile("touchFile", True))
            self.assertTrue(os.path.isfile("touchFile"))

            print("Test if touch updates the mod time")

            st = os.stat("touchFile")
            oldTime = st.st_mtime

            time.sleep(1)

            self.assertTrue(Tf.TouchFile("touchFile", False))

            st = os.stat("touchFile")
            newTime = st.st_mtime

            # Mod time should have been updated by the Has() call.
            self.assertTrue(newTime > oldTime)

        finally:
            if os.path.isfile("touchFile"):
                os.remove("touchFile")
示例#2
0
    def SetupDirStructure(self, structure, withSymlink=False):
        """Create a dir structure for testing"""
        self.log.info("Creating test directory structure...")
        for path, dirs, files in structure:
            if not os.path.isdir(path):
                print 'os.makedirs(%s)' % path
                os.makedirs(path)
        
            for d in [os.path.join(path, d) for d in dirs]:
                if not os.path.isdir(d):
                    print 'os.makedirs(%s)' % d
                    os.makedirs(d)
        
            for f in [os.path.join(path, f) for f in files]:
                if not os.path.isfile(f):
                    Tf.TouchFile(f, True)

        if withSymlink:
            (path, testDir, testFile) = structure[0]
            testFile = os.path.join(os.getcwd(), "linkTarget")
            link = os.path.join(path, "symlink")
            self.CreateFile(testFile, "link")
            self.CreateSymlink(testFile, link)