Esempio n. 1
0
def test_example_data_rectangles() -> None:
    """This test sorts the subtrees, because different operating systems have
    different behaviours with os.listdir.

    """
    tree = FileSystemTree(EXAMPLE_PATH)
    _sort_subtrees(tree)

    tree.update_rectangles((0, 0, 200, 100))
    rects = tree.get_rectangles()

    assert len(rects) == 6

    # UPDATED:
    # Here, we illustrate the correct order of the returned rectangles.
    # Note that this corresponds to the folder contents always being
    # sorted in alphabetical order. This is enforced in these sample tests
    # only so that you can run them on your own comptuer, rather than on
    # the Teaching Labs.
    actual_rects = [r[0] for r in rects]
    expected_rects = [(0, 0, 94, 2), (0, 2, 94, 28), (0, 30, 94, 70),
                      (94, 0, 76, 100), (170, 0, 30, 72), (170, 72, 30, 28)]

    assert len(actual_rects) == len(expected_rects)
    for i in range(len(actual_rects)):
        assert expected_rects[i] == actual_rects[i]
Esempio n. 2
0
def test_task4_update_data_size():
    path = 'example-directory'
    file_tree = FileSystemTree(path)
    file_tree.update_rectangles((0, 0, 800, 600))
    draft = file_tree._subtrees[0]._subtrees[1]
    draft.data_size = 61
    assert file_tree.update_data_sizes() == 154
Esempio n. 3
0
def test_example_data_rectangles() -> None:
    """This test sorts the subtrees, because different operating systems have
    different behaviours with os.listdir.

    You should *NOT* do any sorting in your own code
    """
    tree = FileSystemTree(EXAMPLE_PATH)
    _sort_subtrees(tree)

    tree.update_rectangles((0, 0, 200, 100))
    rects = tree.get_rectangles()

    # IMPORTANT: This test should pass when you have completed Task 2, but
    # will fail once you have completed Task 5.
    # You should edit it as you make progress through the tasks,
    # and add further tests for the later task functionality.
    assert len(rects) == 6

    # UPDATED:
    # Here, we illustrate the correct order of the returned rectangles.
    # Note that this corresponds to the folder contents always being
    # sorted in alphabetical order. This is enforced in these sample tests
    # only so that you can run them on your own comptuer, rather than on
    # the Teaching Labs.
    actual_rects = [r[0] for r in rects]
    expected_rects = [(0, 0, 94, 2), (0, 2, 94, 28), (0, 30, 94, 70),
                      (94, 0, 76, 100), (170, 0, 30, 72), (170, 72, 30, 28)]

    assert len(actual_rects) == len(expected_rects)
    for i in range(len(actual_rects)):
        assert expected_rects[i] == actual_rects[i]
Esempio n. 4
0
def test_task4():
    path = 'example-directory'
    file_tree = FileSystemTree(path)
    file_tree.update_rectangles((0, 0, 800, 600))
    q = file_tree._subtrees[0]._subtrees[0]._subtrees[0]._subtrees[0]
    assert q._name == 'Q2.pdf'
    q.change_size(0.01)
    assert q._parent_tree.data_size == 70
    assert q._parent_tree._parent_tree.data_size == 72
    assert q._parent_tree._parent_tree._parent_tree.datasize == 152
Esempio n. 5
0
def test_single_file_rectangles(x, y, width, height) -> None:
    """Test that the correct rectangle is produced for a single file."""
    tree = FileSystemTree(os.path.join(EXAMPLE_PATH, 'draft.pptx'))
    tree.update_rectangles((x, y, width, height))
    rects = tree.get_rectangles()

    # This should be just a single rectangle and colour returned.
    assert len(rects) == 1
    rect, colour = rects[0]
    assert rect == (x, y, width, height)
    assert is_valid_colour(colour)
Esempio n. 6
0
def run_treemap_file_system(path: str) -> None:
    """Run a treemap visualisation for the given path's file structure.

    Precondition: <path> is a valid path to a file or folder.
    """
    file_tree = FileSystemTree(path)
    run_visualisation(file_tree)
Esempio n. 7
0
def test_empty_file_tree() -> None:
    tree = FileSystemTree('h')
    assert tree._name == 'h'
    assert tree._parent_tree is None
    assert tree._subtrees == []
    assert tree.data_size == 0
    assert is_valid_colour(tree._colour)
Esempio n. 8
0
def test_single_file() -> None:
    """Test a tree with a single file.
    """
    tree = FileSystemTree(os.path.join(EXAMPLE_PATH, 'draft.pptx'))
    assert tree._name == 'draft.pptx'
    assert tree._subtrees == []
    assert tree._parent_tree is None
    assert tree.data_size == 58
    assert is_valid_colour(tree._colour)
Esempio n. 9
0
def test_single_file_rectangles(x, y, width, height) -> None:
    """Test that the correct rectangle is produced for a single file."""
    tree = FileSystemTree('example-directory')
    tree.update_rectangles((x, y, width, height))
    rects = tree.get_rectangles()

    # This should be just a single rectangle and colour returned.
    assert len(rects) == 1
    tree.expand_all()
    rects = tree.get_rectangles()
    assert len(rects) == 6
Esempio n. 10
0
def test_example_data() -> None:
    """Test the root of the tree at the 'workshop' folder in the example data
    """
    tree = FileSystemTree(EXAMPLE_PATH)
    assert tree._name == 'workshop'
    assert tree._parent_tree is None
    assert tree.data_size == 151
    assert is_valid_colour(tree._colour)

    assert len(tree._subtrees) == 3
    for subtree in tree._subtrees:
        # Note the use of is rather than ==.
        # This checks ids rather than values.
        assert subtree._parent_tree is tree
Esempio n. 11
0
 def setUp(self):
     self.path = os.path.join('example-directory', "workshop")
     self.FileTree = FileSystemTree(self.path)
Esempio n. 12
0
def test_task3():
    path = 'example-directory'
    file_tree = FileSystemTree(path)
    file_tree.update_rectangles((0, 0, 800, 600))
    file_tree.get_tree_at_position((376, 168))
    file_tree.get_tree_at_position((377, 168))
Esempio n. 13
0
import os
import math
from tm_trees import FileSystemTree
from papers import PaperTree

s = PaperTree('CS1', [], all_papers=True)
s.update_rectangles((0, 0, 1800, 900))
# print(s._subtrees[1]._subtrees[2].data_size)
r = FileSystemTree('example-directory')
r.update_rectangles((0, 0, 1800, 900))
s.expand_all()
r.expand_all()
print(r.get_rectangles())
print('' '' '' '' '' '')
print(len(s.get_rectangles()))