コード例 #1
0
    def test_print_tree(self):
        path = '/home/Downloads'
        total_size = 1

        file_tree_node = {
            'print_size': '100.00Kb',
            'children': [],
            'size': total_size
        }

        file_tree = {path: file_tree_node}

        largest_size = 2
        catched = StringIO.StringIO()
        sys.stdout = catched

        diskspace.print_tree(
            file_tree,
            file_tree_node,
            path,
            largest_size,
            total_size,
        )

        expected_exit = '100.00Kb  100%  {}\n'.format(path)
        sys.stdout = sys.__stdout__

        self.assertEqual(catched.getvalue(), expected_exit)
コード例 #2
0
 def test_print_tree(self):
     capturedOutput = StringIO.StringIO()
     sys.stdout = capturedOutput
     print_tree(self.file_tree, self.file_tree[self.path], self.path,
                self.largest_size, self.total_size)
     sys.stdout = sys.__stdout__
     self.assertEqual('50.00Kb   75%  ' + self.path,
                      capturedOutput.getvalue().strip())
コード例 #3
0
ファイル: test.py プロジェクト: TecProg-20181/05--gustavo2795
 def print_tree_test(self):
     cap = StringIO.StringIO()
     sys.stdout = cap
     print_tree(self.file_tree, self.file_tree_node, self.path,
                self.largest_size, self.total_size)
     result = "2.00Kb  100%  /home/teste\n"
     sys.stdout = sys.__stdout__
     self.assertEqual(result, cap.getvalue())
コード例 #4
0
ファイル: test.py プロジェクト: TecProg-20181/05--joao4018
 def test_print_tree_two(self):
     capturedOutput = StringIO.StringIO()
     sys.stdout = capturedOutput
     diskspace.print_tree(self.file_tree,
                          self.file_tree_two[self.abs_directory],
                          self.abs_directory, self.largest_size,
                          self.total_size)
     sys.stdout = sys.__stdout__
     self.assertEqual('', capturedOutput.getvalue().strip())
コード例 #5
0
    def test_print_tree(self):
        stdout_ = sys.stdout
        output = cStringIO.StringIO()
        sys.stdout = output
        file_tree_node = {'children': [], 'size': 4, 'print_size': '200.00Kb'}

        file_tree = {'some/directory': file_tree_node}

        diskspace.print_tree(file_tree, file_tree_node, 'some/directory', 4, 4)
        expected_output = '200.00Kb  100%  some/directory\n'
        sys.stdout = stdout_
        self.assertEqual(expected_output, output.getvalue())
コード例 #6
0
    def test_print_tree(self):
        largest_size = 8
        total_size = 4
        cmd = 'du '
        path = os.path.abspath('.')
        cmd += path
        file_tree = {path: {'print_size': '1.00Kb', 'children': [], 'size': 4}}

        capturedOutput = StringIO.StringIO()
        sys.stdout = capturedOutput
        
        print_tree(file_tree, file_tree[path], path, largest_size, total_size)
        
        sys.stdout = sys.__stdout__
        self.assertEqual('1.00Kb  100%  '+ path, capturedOutput.getvalue().strip())
コード例 #7
0
ファイル: test.py プロジェクト: TecProg-20181/05--LucasSiqz
    def test_print_tree(self):
        path = '/home/Documentos'
        total_size = 2
        file_tree_node = {'print_size': '100.00Kb',
                               'children': [], 'size': total_size}
        file_tree = {path: file_tree_node}
        largest_size = 4
        captured = StringIO.StringIO()
        sys.stdout = captured

        diskspace.print_tree(file_tree, file_tree_node, path,
                             largest_size, total_size)

        result = "100.00Kb  100%  {}\n".format(path)
        sys.stdout = sys.__stdout__
        self.assertEqual(result, captured.getvalue())
コード例 #8
0
    def test_print_tree(self):
        file_tree = {}

        file_tree_node = {
            'print_size': '2.00Kb',
            'children': ['/home/folder1'],
            'size': 4
        }

        file_tree = {
            '/home': {
                'print_size': '24.00Kb',
                'children': ['/home/folder1'],
                'size': 48
            },
            "/home/folder1": {
                'print_size': '1.00Kb',
                'children': [],
                'size': 2
            }
        }

        path = '/home'

        largest_size = 7

        total_size = 48

        captured_output = StringIO.StringIO()
        sys.stdout = captured_output

        result = ' 2.00Kb    8%  /home\n 1.00Kb    4%  /home/folder1\n'

        diskspace.print_tree(file_tree, file_tree_node, path, largest_size,
                             total_size)

        sys.stdout = sys.__stdout__

        self.assertEqual(result, captured_output.getvalue())
コード例 #9
0
    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)