def test_subprocess_check_output(self): cmd = 'du -d 1 .' subprocess_return = subprocess.check_output(cmd.strip().split(' ')) diskspace_check_output_return = diskspace.subprocess_check_output(cmd) self.assertEqual(subprocess_return, diskspace_check_output_return)
def test_subprocess_check(self): """ test return type """ command = 'du -d 1' message = diskspace.subprocess_check_output(command) self.assertIsInstance(message, str)
def test_subprocess_check_output(self): depth = -1 abs_directory = os.path.abspath('.') string = 'du ' if depth != -1: string += '-d {} '.format(depth) string += abs_directory result = subprocess.check_output(string.strip().split(' ')) self.assertEqual(subprocess_check_output(string),result)
def subprocess_check_output_test(self): command = 'du' du_result = subprocess.check_output(command) result = subprocess_check_output(command) self.assertEqual(du_result, result)
def test_subprocess_check_output(self): command = 'ls' check = subprocess.check_output(command) self.assertEqual(diskspace.subprocess_check_output(command), check)
def test_subprocess_check_output(self): cmd = 'du' raw_output = subprocess.check_output(cmd) result = subprocess_check_output(cmd) self.assertEqual(raw_output, result)
def test_subprocess_check_output(self): result = diskspace.subprocess_check_output(self.command) results = subprocess_check_output('du -d 1 {}'.format( self.abs_directory)) self.assertEqual(result, results)
def test_subprocess_check_output(self): func = subprocess_check_output('pwd') cwd = os.getcwd() + '\n' self.assertEquals(cwd, func)
def test_raises_error_for_invalid_command(self): command = '1' with self.assertRaises(OSError): output = diskspace.subprocess_check_output(command)
def subprocess_check_output(self): command = 'du ' subprocess = subprocess_check_output(command) self.assertIsInstance(command, str)
def test_subprocess_check_output(self): command = 'du -d 1 /home/filipe/Documentos' result = diskspace.subprocess_check_output(command) test = subprocess.check_output(command.strip().split(' ')) self.assertEqual(result, test)
def test_subprocess_check_output(self): cmd = 'ls' expected = subprocess.check_output(cmd) result = diskspace.subprocess_check_output(cmd) self.assertEqual(expected, result)
def test_subprocess_check_output(self): directory = diskspace.subprocess_check_output(self.cmd) self.assertIn(self.abs_directory, directory)
def test_subprocess_check_output(self): command = "du -d 1 /home/joao/Documentos/UnB/6º_semestre/Tecprog/05--joaovitor3/diskspace" self.assertEqual(diskspace.subprocess_check_output(command),"16\t"+\ "/home/joao/Documentos/UnB/6º_semestre/Tecprog/05--joaovitor3/diskspace"+\ "/__pycache__"+"\n"+"40\t"+"/home/joao/Documentos/UnB/6º_semestre/Tecprog/05--joaovitor3/diskspace"+'\n')
def test_subprocess_check_output(self): cmd = 'ls' result_sub = subprocess.check_output(cmd) result_fuc = diskspace.subprocess_check_output(cmd) self.assertEqual(result_sub, result_fuc)
def test_subprocess_check(self): f_output = diskspace.subprocess_check_output('du -d 1') subprocess_output = subprocess.check_output(['du', '-d', '1']) self.assertEqual(f_output, subprocess_output)
def test_subprocess_check_output(self): path = subprocess_check_output(self.cmd) self.assertIn(self.path, path)
def test_print_tree(self): depth = -1 order = True abs_directory = os.path.abspath('.') cmd = 'du ' if depth != -1: cmd += '-d {} '.format(depth) cmd += abs_directory raw_output = subprocess_check_output(cmd) total_size = -1 line_regex = r'(\d+)\s+([^\s]*|\D*)' file_tree = {} for line in re.findall(line_regex, raw_output.strip(), re.MULTILINE): file_path = line[-1] dir_path = os.path.dirname(file_path) file_size = int(line[0]) if file_path == abs_directory: total_size = file_size if file_path in file_tree: file_tree[file_path]['size'] = file_size else: file_tree[file_path] = { 'children': [], 'size': file_size, } continue if file_path not in file_tree: file_tree[file_path] = { 'children': [], 'size': file_size, } if dir_path not in file_tree: file_tree[dir_path] = { 'children': [], 'size': 0, } file_tree[dir_path]['children'].append(file_path) file_tree[file_path]['size'] = file_size largest_size = 0 for file_path in file_tree: file_tree_entry = file_tree[file_path] file_tree_entry['children'] = sorted( file_tree_entry['children'], key=lambda v: file_tree[v]['size'], reverse=order) file_tree_entry['print_size'] = bytes_to_readable( file_tree_entry['size']) largest_size = max(largest_size, len(file_tree_entry['print_size'])) self.assertNotIsInstance( print_tree(file_tree, file_tree[abs_directory], abs_directory, largest_size, total_size), str)
def test_subprocess_check_output(self): command = 'du -d 1 /home/daniel/Documentos/tecprog/05--danielmarques28' output = subprocess_check_output(command) self.assertEqual(str, type(output)) self.assertIsNot('', output)
def test_subprocess_check_output(self): command = 'ls' expected_exit = subprocess.check_output(command) self.assertEqual(diskspace.subprocess_check_output(command), expected_exit)
def test_subprocess_check_output(self): command = 'du' diskspace_output = subprocess_check_output(command) subprocess_output = subprocess.check_output(command) self.assertEquals(diskspace_output, subprocess_output)
def test_display_correct_output_for_command(self): command = 'echo test' output = diskspace.subprocess_check_output(command) self.assertEqual('test\n', output)
def test_subprocess_check_output(self): cmd = 'du ' subprocess = subprocess_check_output(cmd) self.assertIsInstance(cmd, str)
def test_subprocess_check_output_error(self): with self.assertRaises(OSError): subprocess_check_output('not')