def test_windows_invalid_basenames(self): '''Test whether Windows filenames using a DOS device as basename are invalid''' fs = SystemFS() invalids = itertools.chain(('CON', 'PRN', 'AUX', 'CLOCK$', 'NUL', ), ('COM%d' % i for i in xrange(1, 9)), ('LPT%d' % i for i in xrange(1, 9)) ) for invalid in invalids: self.assertFalse(fs.validateFilename('%s.txt' % invalid, platform=PlatformType.WIN))
def test_windows_invalid_characters(self): '''Test whether a Windows filename containing invalid characters is invalid''' fs = SystemFS() for i in xrange(30): self.assertFalse(fs.validateFilename('abc%s.txt' % chr(i), platform=PlatformType.WIN)) for c in ('<', '>', ':', '"', '/', '\\', '|', '?', '*', ): self.assertFalse(fs.validateFilename('abc%s.txt' % c, platform=PlatformType.WIN))
def wrapper(self, *args, **kwargs): #By the end of May (says Jochen) this should become #raise DeprecationWarning pylabs.q.logger.log( 'Using deprecated method %s on System' % f.__name__, 5) s = SystemFS() return f(s, *args, **kwargs)
def __init__(self): '''Initializes a new System instance Binds currently running L{pylabs.enumerators.PlatformType.PlatformType} and initializes the C{fs}, C{net} and C{process} attributes. ''' self._qPlatformType = PlatformType.findPlatformType() self.fs = SystemFS() self.net = SystemNet() self.string = String() self.process = SystemProcess() if sys.platform.startswith('win'): self.windows = WindowsSystem() else: self.unix = UnixSystem()
def test_lock_timeout(self): '''Test whether lock times out correctly''' fs = SystemFS() events = list() la = TestLocking.LockAcquirer('a1', events, fs, sleeptime=10) lf = TestLocking.LockAcquirer('a2', events, fs, timeout=2) la.start() time.sleep(1) lf.start() la.join() lf.join() self.assertEqual(events, [ {'name': 'a1', 'event': TestLocking.LockAcquirer.GOTLOCK}, {'name': 'a2', 'event': TestLocking.LockAcquirer.LOCKFAIL}, {'name': 'a1', 'event': TestLocking.LockAcquirer.RELEASEDLOCK}, ])
def test_standard_lock(self): '''Test locking using default parameters''' fs = SystemFS() events = list() threadEvent = threading.Event() threadEvent.set() la = TestLocking.LockAcquirer('a1', events, fs, threadEvent=threadEvent) lf = TestLocking.LockAcquirer('a2', events, fs, threadEvent=threadEvent) la.start() time.sleep(1) lf.start() la.join() lf.join() self.assertEqual(events, [ {'name': 'a1', 'event': TestLocking.LockAcquirer.GOTLOCK}, {'name': 'a1', 'event': TestLocking.LockAcquirer.RELEASEDLOCK}, {'name': 'a2', 'event': TestLocking.LockAcquirer.GOTLOCK}, {'name': 'a2', 'event': TestLocking.LockAcquirer.RELEASEDLOCK} ])
def test_windows_invalid_ending_dot(self): '''Test whether a Windows filename ending with a dot is invalid''' fs = SystemFS() self.assertFalse(fs.validateFilename('test.txt.', platform=PlatformType.WIN))
def test_windows_invalid_length(self): '''Test whether a Windows filename of 256 characters is invalid''' fs = SystemFS() filename = 'a' * 256 self.assertFalse(fs.validateFilename(filename, platform=PlatformType.WIN))
def test_windows_valid(self): '''Test whether a complex but valid Windows filename is valid''' fs = SystemFS() filename = 'This is a valid Wind0ws filename with some characters like ^{[]' self.assert_(fs.validateFilename(filename, platform=PlatformType.WIN))
def test_unix_invalid_length(self): '''Test whether a UNIX filename of 256 characters is invalid''' fs = SystemFS() filename = 'a' * 256 self.assertFalse(fs.validateFilename(filename, platform=PlatformType.UNIX))
def test_unix_invalid_slash(self): '''Test whether a UNIX filename containing / is invalid''' fs = SystemFS() filename = 'foo/bar.txt' self.assertFalse(fs.validateFilename(filename, platform=PlatformType.UNIX))
def test_unix_valid(self): '''Test whether a complex but valid UNIX filename is valid''' fs = SystemFS() filename = '.test_kf456\';.,^$&@(@' self.assert_(fs.validateFilename(filename, platform=PlatformType.UNIX))
def test_generic_invalid_empty(self): '''Test whether an empty filename is invalid''' fs = SystemFS() filename = '' self.assertFalse(fs.validateFilename(filename))
def test_dir(self): fs=SystemFS() fs.createDir(os.path.join(q.dirs.tmpDir, "unit_test")) self.assert_(os.path.exists(os.path.join(q.dirs.tmpDir, "unit_test")), "q.system.fs.createDir: dir was not created") fs.removeDir(os.path.join(q.dirs.tmpDir, "unit_test")) self.failIf(os.path.exists(os.path.join(q.dirs.tmpDir, "unit_test")), "q.system.removeDir: dir was not removed")
def test_exists(self): fs=SystemFS() self.assertEqual(fs.exists(q.dirs.tmpDir), os.path.exists(q.dirs.tmpDir), "q.system.fs.exists() failed")
def test_isDir(self): fs=SystemFS() self.assertEqual(fs.isDir(q.dirs.tmpDir), os.path.isdir(q.dirs.tmpDir), "The q.system.fs.isDir() failed")
def test_unsupported_platform(self): '''Test whether checking against an unsupported platform raises an error''' fs = SystemFS() self.assertRaises(NotImplementedError, fs.validateFilename, 'test', platform=PlatformType.OTHER)
def test_unix_invalid_null(self): '''Test whether a UNIX filename containing null is invalid''' fs = SystemFS() filename = 'foo.bar\0.baz' self.assertFalse(fs.validateFilename(filename, platform=PlatformType.UNIX))