コード例 #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]
コード例 #2
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]
コード例 #3
0
ファイル: my_a2_test.py プロジェクト: Jimmyzz2/csc148
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
コード例 #4
0
ファイル: my_a2_test.py プロジェクト: Jimmyzz2/csc148
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
コード例 #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)
コード例 #6
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
コード例 #7
0
ファイル: my_a2_test.py プロジェクト: Jimmyzz2/csc148
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))
コード例 #8
0
ファイル: os_practice.py プロジェクト: tmayer2000/a2-CSC148
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()))