예제 #1
0
 def test_map_between_where_src_parent_is_dest(self):
     destination = InvisibleObject((Unit(3), Unit(10)),
                                   neoscore.document.pages[0])
     source = InvisibleObject((Unit(1), Unit(2)), destination)
     relative_pos = map_between(source, destination)
     expected = Point(Unit(-1), Unit(-2))
     assert_almost_equal(relative_pos, expected)
예제 #2
0
 def test_length_with_parents(self):
     parent_1 = InvisibleObject((Unit(1), Unit(2)), None)
     parent_2 = InvisibleObject((Unit(11), Unit(12)), None)
     spanner = MockSpanner2D(
         Point(Unit(1), Unit(2)), parent_1, Point(Unit(4), Unit(5)), parent_2
     )
     # math.sqrt(((15-2)**2) + ((17-4)**2))
     assert_almost_equal(spanner.spanner_2d_length, Unit(18.384776310850235))
예제 #3
0
 def test_map_between_with_common_parent(self):
     parent = InvisibleObject((Unit(5), Unit(6)),
                              neoscore.document.pages[0])
     source = InvisibleObject((Unit(1), Unit(2)), parent)
     destination = InvisibleObject((Unit(3), Unit(10)), parent)
     relative_pos = map_between(source, destination)
     expected = Point(Unit(2), Unit(8))
     assert_almost_equal(relative_pos, expected)
예제 #4
0
    def test_map_between(self):
        source = InvisibleObject((Unit(5), Unit(6)),
                                 neoscore.document.pages[1])
        destination = InvisibleObject((Unit(99), Unit(90)),
                                      neoscore.document.pages[4])
        relative_pos = map_between(source, destination)

        page_1_pos = canvas_pos_of(neoscore.document.pages[1])
        page_4_pos = canvas_pos_of(neoscore.document.pages[4])

        expected = (page_4_pos + Point(Unit(99), Unit(90))) - (
            page_1_pos + Point(Unit(5), Unit(6)))
        assert_almost_equal(relative_pos, expected)
예제 #5
0
 def test_descendants(self):
     root = InvisibleObject((Unit(0), Unit(0)))
     child_1 = InvisibleObject((Unit(0), Unit(0)), parent=root)
     child_2 = InvisibleObject((Unit(0), Unit(0)), parent=root)
     subchild_1 = InvisibleObject((Unit(0), Unit(0)), parent=child_2)
     subchild_2 = InvisibleObject((Unit(0), Unit(0)), parent=child_2)
     descendants = list(root.descendants)
     descendants_set = set(descendants)
     # Assert no duplicates were yielded
     assert len(descendants) == len(descendants_set)
     # Assert root itself was not in the descendants list
     assert root not in descendants_set
     # Assert descendants content
     assert {child_1, child_2, subchild_1, subchild_2} == descendants_set
예제 #6
0
    def test_descendants_with_attribute(self):
        class MockDifferentClass(InvisibleObject):
            test_attr = 1

        root = InvisibleObject((Unit(0), Unit(0)))
        child_1 = InvisibleObject((Unit(0), Unit(0)), parent=root)
        child_2 = MockDifferentClass((Unit(0), Unit(0)), parent=root)
        descendants = list(root.descendants_with_attribute("test_attr"))
        descendants_set = set(descendants)
        # Assert no duplicates were yielded
        assert len(descendants) == len(descendants_set)
        # Assert root itself was not in the descendants list
        assert root not in descendants_set
        # Assert descendants content
        assert {child_2} == descendants_set
예제 #7
0
파일: test_path.py 프로젝트: ajyoon/brown
 def test_init(self):
     mock_parent = InvisibleObject(ORIGIN, parent=None)
     test_pen = Pen("#eeeeee")
     test_brush = Brush("#dddddd")
     path = Path((Unit(5), Unit(6)), test_pen, test_brush, mock_parent)
     assert path.pos == Point(Unit(5), Unit(6))
     assert path.pen == test_pen
     assert path.brush == test_brush
예제 #8
0
파일: test_path.py 프로젝트: ajyoon/brown
 def test_move_to_with_parent(self):
     path = Path(ORIGIN)
     parent = InvisibleObject((Unit(100), Unit(50)))
     path.move_to(Unit(10), Unit(11), parent)
     assert len(path.elements) == 1
     assert_path_els_equal(
         path.elements[0], MoveTo(Point(Unit(10), Unit(11)), parent)
     )
예제 #9
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=self.staff)
     test_object = MusicText((Unit(5), Unit(6)), "accidentalFlat",
                             mock_parent, self.font)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.text == "\ue260"
     assert test_object.font == self.font
     assert test_object.parent == mock_parent
예제 #10
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=None)
     test_object = Text((Unit(5), Unit(6)), "testing", self.font,
                        mock_parent)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.text == "testing"
     assert test_object.font == self.font
     assert test_object.parent == mock_parent
예제 #11
0
파일: test_path.py 프로젝트: ajyoon/brown
 def test_line_to_with_parent(self):
     path = Path((Unit(5), Unit(6)))
     parent = InvisibleObject((Unit(100), Unit(50)))
     path.line_to(Unit(1), Unit(3), parent)
     assert path.elements[-1].parent == parent
     resolved_els = path._resolve_path_elements()
     assert resolved_els == [
         ResolvedMoveTo(ZERO, ZERO),
         ResolvedLineTo(Unit(100 + 1 - 5), Unit(50 + 3 - 6)),
     ]
예제 #12
0
파일: test_path.py 프로젝트: ajyoon/brown
 def test_cubic_to_with_parents(self):
     path = Path((Unit(Unit(100)), Unit(Unit(200))))
     parent_1 = InvisibleObject((Unit(Unit(10)), Unit(Unit(20))))
     parent_2 = InvisibleObject((Unit(Unit(30)), Unit(Unit(40))))
     parent_3 = InvisibleObject((Unit(Unit(50)), Unit(Unit(60))))
     path.cubic_to(
         Unit(1),
         Unit(2),
         Unit(3),
         Unit(4),
         Unit(5),
         Unit(6),
         parent_1,
         parent_2,
         parent_3,
     )
     assert len(path.elements) == 2
     assert_path_els_equal(path.elements[0], MoveTo(ORIGIN, path))
     assert_path_els_equal(
         path.elements[1],
         CurveTo(
             ControlPoint(Point(Unit(1), Unit(2)), parent_1),
             ControlPoint(Point(Unit(3), Unit(4)), parent_2),
             Point(Unit(5), Unit(6)),
             parent_3,
         ),
     )
     resolved_els = path._resolve_path_elements()
     assert resolved_els == [
         ResolvedMoveTo(ZERO, ZERO),
         ResolvedCurveTo(
             Unit(10 + 1 - 100),
             Unit(20 + 2 - 200),
             Unit(30 + 3 - 100),
             Unit(40 + 4 - 200),
             Unit(50 + 5 - 100),
             Unit(60 + 6 - 200),
         ),
     ]
예제 #13
0
    def test_descendants_of_exact_class(self):
        # Use two new mock classes for type filter testing
        class MockDifferentClass1(InvisibleObject):
            pass

        class MockDifferentClass2(MockDifferentClass1):
            pass

        root = InvisibleObject((Unit(0), Unit(0)))
        child_1 = InvisibleObject((Unit(0), Unit(0)), parent=root)
        child_2 = MockDifferentClass1((Unit(0), Unit(0)), parent=root)
        subchild_1 = MockDifferentClass2((Unit(0), Unit(0)), parent=child_2)
        subchild_2 = MockDifferentClass2((Unit(0), Unit(0)), parent=child_2)
        descendants = list(
            root.descendants_of_exact_class(MockDifferentClass1))
        descendants_set = set(descendants)
        # Assert no duplicates were yielded
        assert len(descendants) == len(descendants_set)
        # Assert root itself was not in the descendants list
        assert root not in descendants_set
        # Assert descendants content
        assert {child_2} == descendants_set
예제 #14
0
 def test_canvas_pos_of(self):
     item = InvisibleObject((Mm(5), Mm(6)), neoscore.document.pages[2])
     canvas_pos = canvas_pos_of(item)
     page_pos = canvas_pos_of(neoscore.document.pages[2])
     relative_pos = canvas_pos - page_pos
     assert_almost_equal(relative_pos, Point(Mm(5), Mm(6)))
예제 #15
0
 def test_unregister_child(self):
     parent = InvisibleObject((Unit(0), Unit(0)))
     child = InvisibleObject((Unit(0), Unit(0)))
     parent.children = {child}
     parent._unregister_child(child)
     assert child not in parent.children
예제 #16
0
 def test_setting_parent_registers_self_with_parent(self):
     parent = InvisibleObject((Unit(0), Unit(0)))
     child = InvisibleObject((Unit(0), Unit(0)), parent=parent)
     assert child in parent.children
예제 #17
0
 def test_register_child(self):
     parent = InvisibleObject((Unit(0), Unit(0)))
     child = InvisibleObject((Unit(0), Unit(0)))
     parent._register_child(child)
     assert child in parent.children
예제 #18
0
 def test_pos_setter_changes_x(self):
     grob = InvisibleObject((Unit(5), Unit(6)))
     grob.pos = Point(Unit(7), Unit(8))
     assert grob.pos == Point(Unit(7), Unit(8))
예제 #19
0
 def __init__(self, pos, parent):
     InvisibleObject.__init__(self, pos, parent)
     StaffObject.__init__(self, parent)
예제 #20
0
 def test_init(self):
     mock_parent = InvisibleObject((Unit(10), Unit(11)), parent=None)
     test_object = InvisibleObject((Unit(5), Unit(6)), parent=mock_parent)
     assert test_object.x == GraphicUnit(5)
     assert test_object.y == GraphicUnit(6)
     assert test_object.parent == mock_parent
예제 #21
0
 def test_map_between_with_same_source_and_dest(self):
     obj = InvisibleObject((Unit(5), Unit(6)), neoscore.document.pages[0])
     assert_almost_equal(map_between(obj, obj), Point(Unit(0), Unit(0)))