def testLsDirectoryNotExist(self): self.path = 'test/toto' self.options['all'] = False self.options['recursive'] = False self.options['onlyDir'] = False self.options['long'] = False self.options['reverse'] = False self.options['count'] = False with self.assertRaises(OSError): ls.ls(self.path, self.options)
def testLsDirectoryDefault(self): self.path = '.' capturedOutput = io.StringIO() # Create StringIO object sys.stdout = capturedOutput # and redirect stdout. self.options['all'] = False self.options['recursive'] = False self.options['onlyDir'] = False self.options['long'] = False self.options['reverse'] = False self.options['count'] = False expectedOutput = ['README.md', 'src', 'test'] with contextlib.redirect_stdout(capturedOutput): ls.ls(self.path, self.options) sys.stdout = sys.__stdout__ # Reset redirect self.assertEqual(len(expectedOutput), len(capturedOutput.getvalue().split())) self.assertEqual(expectedOutput, capturedOutput.getvalue().split())
def testLsOnlyDir(self): capturedOutput = io.StringIO() # Create StringIO object sys.stdout = capturedOutput # and redirect stdout. self.options['all'] = False self.options['recursive'] = False self.options['onlyDir'] = True self.options['long'] = False self.options['reverse'] = False self.options['count'] = False expectedOutput = [ '.', '..', '.zombie', 'clients', 'daemon', 'includes', 'obj', 'src', '9', 'files' ] with contextlib.redirect_stdout(capturedOutput): ls.ls(self.path, self.options) sys.stdout = sys.__stdout__ # Reset redirect self.assertEqual(len(expectedOutput), len(capturedOutput.getvalue().split())) self.assertEqual(expectedOutput, capturedOutput.getvalue().split())
def testLsAll(self): capturedOutput = io.StringIO() # Create StringIO object sys.stdout = capturedOutput # and redirect stdout. self.options['all'] = True self.options['recursive'] = False self.options['onlyDir'] = False self.options['long'] = False self.options['reverse'] = False self.options['count'] = False expectedOutput = [ '.', '..', '.ignore', '.zombie', 'Dockerfile', 'Durex', 'Durex.service', 'Makefile', 'README.md', 'clean.sh', 'clients', 'daemon', 'includes', 'obj', 'reset.sh', 'show_log.sh', 'src' ] with contextlib.redirect_stdout(capturedOutput): ls.ls(self.path, self.options) sys.stdout = sys.__stdout__ # Reset redirect self.assertEqual(len(expectedOutput), len(capturedOutput.getvalue().split())) self.assertEqual(expectedOutput, capturedOutput.getvalue().split())