def test_orthogonal_horizontal_undo(self): """Test orthogonal line constraints bug (#107) """ canvas = Canvas() line = Line() canvas.add(line) assert not line.horizontal assert len(canvas.solver._constraints) == 0 segment = Segment(line, None) segment.split_segment(0) line.orthogonal = True self.assertEqual(2, len(canvas.solver._constraints)) after_ortho = set(canvas.solver._constraints) del undo_list[:] line.horizontal = True self.assertEqual(2, len(canvas.solver._constraints)) undo() self.assertFalse(line.horizontal) self.assertEqual(2, len(canvas.solver._constraints)) line.horizontal = True self.assertTrue(line.horizontal) self.assertEqual(2, len(canvas.solver._constraints))
def __init__(self): self.canvas = Canvas() self.box1 = Box() self.canvas.add(self.box1) self.box1.matrix.translate(100, 50) self.box1.width = 40 self.box1.height = 40 self.box1.request_update() self.box2 = Box() self.canvas.add(self.box2) self.box2.matrix.translate(100, 150) self.box2.width = 50 self.box2.height = 50 self.box2.request_update() self.line = Line() self.head = self.line.handles()[0] self.tail = self.line.handles()[-1] self.tail.pos = 100, 100 self.canvas.add(self.line) self.canvas.update_now() self.view = GtkView() self.view.canvas = self.canvas self.win = Gtk.Window() self.win.add(self.view) self.view.show() self.view.update() self.win.show() self.tool = ConnectHandleTool(self.view)
def test_orthogonal_horizontal_undo(self): """Test orthogonal line constraints bug (#107) """ canvas = Canvas() line = Line() canvas.add(line) assert not line.horizontal assert len(canvas.solver._constraints) == 0 segment = Segment(line, None) segment.split_segment(0) line.orthogonal = True self.assertEquals(2, len(canvas.solver._constraints)) after_ortho = set(canvas.solver._constraints) del undo_list[:] line.horizontal = True self.assertEquals(2, len(canvas.solver._constraints)) undo() self.assertFalse(line.horizontal) self.assertEquals(2, len(canvas.solver._constraints)) line.horizontal = True self.assertTrue(line.horizontal) self.assertEquals(2, len(canvas.solver._constraints))
class SegmentFixture(object): def __init__(self): self.canvas = Canvas() self.line = Line() self.canvas.add(self.line) self.view = View(self.canvas) self.item = Item()
def test_view_registration_2(self): """ Test view registration and destroy when view is destroyed. """ canvas = Canvas() view = GtkView(canvas) window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) window.add(view) window.show_all() box = Box() canvas.add(box) assert hasattr(box, '_matrix_i2v') assert hasattr(box, '_matrix_v2i') assert box._matrix_i2v[view] assert box._matrix_v2i[view] assert len(canvas._registered_views) == 1 assert view in canvas._registered_views window.destroy() assert len(canvas._registered_views) == 0 assert view not in box._matrix_i2v assert view not in box._matrix_v2i
def test_minimal_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] h_se.pos.x -= 20 # h.se.{x,y} == -10 h_se.pos.y -= 20 assert h_se.pos.x == h_se.pos.y == -10 box.request_update() canvas.update() self.assertEquals(10, h_se.pos.x) # h_se changed above, should be 10 self.assertEquals(10, h_se.pos.y) self.assertEquals(10, h_ne.pos.x) self.assertEquals(10, h_sw.pos.y)
def test_view_registration_2(self): """ Test view registration and destroy when view is destroyed. """ canvas = Canvas() view = GtkView(canvas) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() box = Box() canvas.add(box) assert hasattr(box, '_matrix_i2v') assert hasattr(box, '_matrix_v2i') assert box._matrix_i2v[view] assert box._matrix_v2i[view] assert len(canvas._registered_views) == 1 assert view in canvas._registered_views window.destroy() assert len(canvas._registered_views) == 0 assert not box._matrix_i2v.has_key(view) assert not box._matrix_v2i.has_key(view)
def test_orthogonal_horizontal_undo(self): canvas = Canvas() line = Line() canvas.add(line) assert len(canvas.solver._constraints) == 0 line.orthogonal = True assert len(canvas.solver._constraints) == 2 after_ortho = set(canvas.solver._constraints) del undo_list[:] line.horizontal = True assert len(canvas.solver._constraints) == 2 undo() assert not line.horizontal assert len(canvas.solver._constraints) == 2, canvas.solver._constraints line.horizontal = True assert line.horizontal assert len(canvas.solver._constraints) == 2, canvas.solver._constraints
def test_get_item_at_point(self): """ Hover tool only reacts on motion-notify events """ canvas = Canvas() view = GtkView(canvas) window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) window.add(view) window.show_all() box = Box() canvas.add(box) # No gtk main loop, so updates occur instantly assert not canvas.require_update() box.width = 50 box.height = 50 # Process pending (expose) events, which cause the canvas to be drawn. while Gtk.events_pending(): Gtk.main_iteration() assert len(view._qtree._ids) == 1 assert not view._qtree._bucket.bounds == ( 0, 0, 0, 0), view._qtree._bucket.bounds assert view.get_item_at_point((10, 10)) is box assert view.get_item_at_point((60, 10)) is None window.destroy()
class SegmentFixture: def __init__(self): self.canvas = Canvas() self.line = Line() self.canvas.add(self.line) self.view = View(self.canvas) self.item = Item()
def test_orthogonal_horizontal_undo(revert_undo, undo_fixture): """Test orthogonal line constraints bug (#107). """ canvas = Canvas() line = Line() canvas.add(line) assert not line.horizontal assert len(canvas.solver._constraints) == 0 segment = Segment(line, None) segment.split_segment(0) line.orthogonal = True assert 2 == len(canvas.solver._constraints) del undo_fixture[2][:] # Clear undo_list line.horizontal = True assert 2 == len(canvas.solver._constraints) undo_fixture[0]() # Call undo assert not line.horizontal assert 2 == len(canvas.solver._constraints) line.horizontal = True assert line.horizontal assert 2 == len(canvas.solver._constraints)
class SegmentTestCase(unittest.TestCase): """ Test aspects for items. """ def setUp(self): self.canvas = Canvas() self.view = View(self.canvas) def test_segment_fails_for_item(self): """ Test if Segment aspect can be applied to Item """ item = Item() try: s = Segment(item, self.view) except TypeError as e: pass else: assert False, 'Should not be reached' def test_segment(self): """ """ view = self.view line = Line() self.canvas.add(line) segment = Segment(line, self.view) self.assertEqual(2, len(line.handles())) segment.split((5, 5)) self.assertEqual(3, len(line.handles()))
def test_orthogonal_line_undo(revert_undo, undo_fixture): """Test orthogonal line undo. """ canvas = Canvas() line = Line() canvas.add(line) segment = Segment(line, None) segment.split_segment(0) # Start with no orthogonal constraints assert len(canvas.solver._constraints) == 0 line.orthogonal = True # Check orthogonal constraints assert 2 == len(canvas.solver._constraints) assert 3 == len(line.handles()) undo_fixture[0]() # Call undo assert not line.orthogonal assert 0 == len(canvas.solver._constraints) assert 2 == len(line.handles())
def test_get_item_at_point(self): """ Hover tool only reacts on motion-notify events """ canvas = Canvas() view = GtkView(canvas) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() box = Box() canvas.add(box) # No gtk main loop, so updates occur instantly assert not canvas.require_update() box.width = 50 box.height = 50 # Process pending (expose) events, which cause the canvas to be drawn. while gtk.events_pending(): gtk.main_iteration() assert len(view._qtree._ids) == 1 assert not view._qtree._bucket.bounds == (0, 0, 0, 0), view._qtree._bucket.bounds assert view.get_item_at_point((10, 10)) is box assert view.get_item_at_point((60, 10)) is None window.destroy()
class SegmentHandlesTest(unittest.TestCase): def setUp(self): self.canvas = Canvas() self.line = Line() self.canvas.add(self.line) self.view = View(self.canvas) def testHandleFinder(self): finder = HandleFinder(self.line, self.view) assert type(finder) is SegmentHandleFinder, type(finder)
def test_item_removal(self): canvas = Canvas() view = GtkView(canvas) window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) window.add(view) window.show_all() box = Box() canvas.add(box) # No gtk main loop, so updates occur instantly assert not canvas.require_update() # Process pending (expose) events, which cause the canvas to be drawn. while Gtk.events_pending(): Gtk.main_iteration() assert len(canvas.get_all_items()) == len(view._qtree) view.focused_item = box canvas.remove(box) assert len(canvas.get_all_items()) == 0 assert len(view._qtree) == 0 window.destroy()
def __init__(self): self.canvas = Canvas() self.view = GtkView(self.canvas) self.window = Gtk.Window() self.window.add(self.view) self.window.show_all() self.line = Line() self.canvas.add(self.line) self.e1 = Element() self.e2 = Element() self.e3 = Element()
def test_reparent(): c = Canvas() b1 = Box() b2 = Box() c.add(b1) c.add(b2, b1) c.reparent(b2, None)
def test_item_removal(self): canvas = Canvas() view = GtkView(canvas) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() box = Box() canvas.add(box) # No gtk main loop, so updates occur instantly assert not canvas.require_update() # Process pending (expose) events, which cause the canvas to be drawn. while gtk.events_pending(): gtk.main_iteration() assert len(canvas.get_all_items()) == len(view._qtree) view.focused_item = box canvas.remove(box) assert len(canvas.get_all_items()) == 0 assert len(view._qtree) == 0 window.destroy()
def __init__(self): self.canvas = Canvas() self.view = GtkView(self.canvas) self.window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) self.window.add(self.view) self.window.show_all() self.box = Box() self.canvas.add(self.box) # No gtk main loop, so updates occur instantly assert not self.canvas.require_update() # Process pending (expose) events, which cause the canvas to be drawn. while Gtk.events_pending(): Gtk.main_iteration()
def test_association_end_updates(self): """Test association end navigability connected to a class""" from gaphas.canvas import Canvas canvas = Canvas() c1 = self.create(ClassItem, UML.Class) c2 = self.create(ClassItem, UML.Class) a = self.create(AssociationItem) self.connect(a, a.head, c1) c = self.get_connected(a.head) self.assertTrue(c is c1) self.connect(a, a.tail, c2) c = self.get_connected(a.tail) self.assertTrue(c is c2) assert a.subject.memberEnd, a.subject.memberEnd assert a.subject.memberEnd[0] is a.head_end.subject assert a.subject.memberEnd[1] is a.tail_end.subject assert a.subject.memberEnd[0].name is None dispatcher = self.get_service("element_dispatcher") a.subject.memberEnd[0].name = "blah" self.diagram.canvas.update() assert a.head_end._name == "+ blah", a.head_end.get_name()
def test_association_end_updates(self): """Test association end navigability connected to a class""" from gaphas.canvas import Canvas canvas = Canvas() c1 = self.create(ClassItem, uml2.Class) c2 = self.create(ClassItem, uml2.Class) a = self.create(AssociationItem) self.connect(a, a.head, c1) c = self.get_connected(a.head) self.assertTrue(c is c1) self.connect(a, a.tail, c2) c = self.get_connected(a.tail) self.assertTrue(c is c2) assert a.subject.memberEnd, a.subject.memberEnd assert a.subject.memberEnd[0] is a.head_end.subject assert a.subject.memberEnd[1] is a.tail_end.subject assert a.subject.memberEnd[0].name is None dispatcher = self.get_service('element_dispatcher') print((a.subject.memberEnd[0], uml2.Property.name) in dispatcher._handlers) print('*' * 60) a.subject.memberEnd[0].name = 'blah' print('*' * 60) self.diagram.canvas.update() assert a.head_end._name == '+ blah', a.head_end.get_name()
def test_connect_item(self): b1 = Box() b2 = Box() l = Line() c = Canvas() c.add(b1) c.add(b2) c.add(l) c.connect_item(l, l.handles()[0], b1, b1.ports()[0]) assert count(c.get_connections(handle=l.handles()[0])) == 1 # Add the same self.assertRaises(ConnectionError, c.connect_item, l, l.handles()[0], b1, b1.ports()[0]) assert count(c.get_connections(handle=l.handles()[0])) == 1
def test_get_handle_at_point(self): canvas = Canvas() view = GtkView(canvas) window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) window.add(view) window.show_all() box = Box() box.min_width = 20 box.min_height = 30 box.matrix.translate(20, 20) box.matrix.rotate(old_div(math.pi, 1.5)) canvas.add(box) i, h = view.get_handle_at_point((20, 20)) assert i is box assert h is box.handles()[0]
def test_scroll_adjustments(self): sc = gtk.ScrolledWindow() view = GtkView(Canvas()) sc.add(view) print sc.get_hadjustment(), view.hadjustment assert sc.get_hadjustment() is view.hadjustment assert sc.get_vadjustment() is view.vadjustment
def test_get_handle_at_point(self): canvas = Canvas() view = GtkView(canvas) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() box = Box() box.min_width = 20 box.min_height = 30 box.matrix.translate(20, 20) box.matrix.rotate(math.pi/1.5) canvas.add(box) i, h = view.get_handle_at_point((20, 20)) assert i is box assert h is box.handles()[0]
def test_reparent(self): c = Canvas() b1 = Box() b2 = Box() c.add(b1) c.add(b2, b1) c.reparent(b2, None)
def test_creation_with_size(self): """ Test if initial size holds when added to a canvas. """ canvas = Canvas() box = Box(150, 153) assert box.width == 150, box.width assert box.height == 153, box.height assert box.handles()[SE].pos.x == 150, box.handles()[SE].pos.x assert box.handles()[SE].pos.y == 153, box.handles()[SE].pos.y canvas.add(box) assert box.width == 150, box.width assert box.height == 153, box.height assert box.handles()[SE].pos.x == 150, box.handles()[SE].pos.x assert box.handles()[SE].pos.y == 153, box.handles()[SE].pos.y
def test_orthogonal_line_split_segment(self): canvas = Canvas() line = Line() canvas.add(line) assert len(canvas.solver._constraints) == 0 line.orthogonal = True assert len(canvas.solver._constraints) == 2 after_ortho = set(canvas.solver._constraints) assert len(line.handles()) == 3 del undo_list[:] line.split_segment(0) assert len(canvas.solver._constraints) == 3 assert len(line.handles()) == 4 undo() assert len(canvas.solver._constraints) == 2 assert len(line.handles()) == 3 assert canvas.solver._constraints == after_ortho line.split_segment(0) assert len(canvas.solver._constraints) == 3 assert len(line.handles()) == 4 after_split = set(canvas.solver._constraints) del undo_list[:] line.merge_segment(0) assert len(canvas.solver._constraints) == 2 assert len(line.handles()) == 3 undo() assert len(canvas.solver._constraints) == 3 assert len(line.handles()) == 4 assert canvas.solver._constraints == after_split
def test_scroll_adjustments_signal(self): def handler(self, hadj, vadj): self.handled = True sc = gtk.ScrolledWindow() view = GtkView(Canvas()) view.connect('set-scroll-adjustments', handler) sc.add(view) assert view.handled
def test_view_registration(self): canvas = Canvas() # Simple views do not register on the canvas view = View(canvas) assert len(canvas._registered_views) == 0 box = Box() canvas.add(box) # By default no complex updating/calculations are done: assert not box._matrix_i2v.has_key(view) assert not box._matrix_v2i.has_key(view) # GTK view does register for updates though view = GtkView(canvas) assert len(canvas._registered_views) == 1 # No entry, since GtkView is not realized and has no window assert not box._matrix_i2v.has_key(view) assert not box._matrix_v2i.has_key(view) window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.add(view) window.show_all() # Now everything is realized and updated assert box._matrix_i2v.has_key(view) assert box._matrix_v2i.has_key(view) view.canvas = None assert len(canvas._registered_views) == 0 assert not box._matrix_i2v.has_key(view) assert not box._matrix_v2i.has_key(view) view.canvas = canvas assert len(canvas._registered_views) == 1 assert box._matrix_i2v.has_key(view) assert box._matrix_v2i.has_key(view)
def test_line_guide(self): c = Canvas() l = Line() c.add(l) l.handles().append(l._create_handle((20, 20))) l.handles().append(l._create_handle((30, 30))) l.handles().append(l._create_handle((40, 40))) l.orthogonal = True c.update_now() guides = list(Guide(l).horizontal()) self.assertEquals(2, len(guides)) self.assertEquals(10.0, guides[0]) self.assertEquals(40.0, guides[1]) guides = list(Guide(l).vertical()) self.assertEquals(2, len(guides)) self.assertEquals(00.0, guides[0]) self.assertEquals(20.0, guides[1])
def test_view_registration(view_fixture): canvas = Canvas() # Simple views do not register on the canvas view = View(canvas) assert len(canvas._registered_views) == 0 box = Box() canvas.add(box) # By default no complex updating/calculations are done: assert view not in box._matrix_i2v assert view not in box._matrix_v2i # GTK view does register for updates though view = GtkView(canvas) assert len(canvas._registered_views) == 1 # No entry, since GtkView is not realized and has no window assert view not in box._matrix_i2v assert view not in box._matrix_v2i window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL) window.add(view) window.show_all() # Now everything is realized and updated assert view in box._matrix_i2v assert view in box._matrix_v2i view.canvas = None assert len(canvas._registered_views) == 0 assert view not in box._matrix_i2v assert view not in box._matrix_v2i view.canvas = canvas assert len(canvas._registered_views) == 1 assert view in box._matrix_i2v assert view in box._matrix_v2i
def test_line_projection(self): """Test projection with line's handle on element's side""" line = Line() line.matrix.translate(15, 50) h1, h2 = line.handles() h1.x, h1.y = 0, 0 h2.x, h2.y = 20, 20 box = Box() box.matrix.translate(10, 10) box.width = 40 box.height = 20 h_nw, h_ne, h_se, h_sw = box.handles() canvas = Canvas() canvas.add(line) canvas.add(box) # move line's second handle on box side h2.x, h2.y = 5, -20
def create_canvas(): canvas = Canvas() box = Box() canvas.add(box) box.matrix.translate(100, 50) box.matrix.rotate(50) box2 = Box() canvas.add(box2, parent=box) line = Line() line.handles()[0].visible = False line.handles()[0].connected_to = box line.handles()[0].disconnect = my_disconnect() line.handles()[0].connection_data = 1 canvas.add(line) canvas.update() return canvas
def test_bounding_box_calculations(self): """ A view created before and after the canvas is populated should contain the same data. """ canvas = Canvas() window1 = gtk.Window(gtk.WINDOW_TOPLEVEL) view1 = GtkView(canvas=canvas) window1.add(view1) view1.realize() window1.show_all() box = Box() box.matrix = (1.0, 0.0, 0.0, 1, 10,10) canvas.add(box) line = Line() line.fyzzyness = 1 line.handles()[1].pos = (30, 30) #line.split_segment(0, 3) line.matrix.translate(30, 60) canvas.add(line) window2 = gtk.Window(gtk.WINDOW_TOPLEVEL) view2 = GtkView(canvas=canvas) window2.add(view2) window2.show_all() # Process pending (expose) events, which cause the canvas to be drawn. while gtk.events_pending(): gtk.main_iteration() try: assert view2.get_item_bounding_box(box) assert view1.get_item_bounding_box(box) assert view1.get_item_bounding_box(box) == view2.get_item_bounding_box(box), '%s != %s' % (view1.get_item_bounding_box(box), view2.get_item_bounding_box(box)) assert view1.get_item_bounding_box(line) == view2.get_item_bounding_box(line), '%s != %s' % (view1.get_item_bounding_box(line), view2.get_item_bounding_box(line)) finally: window1.destroy() window2.destroy()
def test_discard(self): """Test removal of an item from Sorted collection""" e1 = Element() e2 = Element() c = Canvas() c.add(e1) c.add(e2) items = Sorted(c) items.add(e1) items.add(e2) assert e1 in items and e2 in items items.discard(e1) items.discard(e1) # silent discard self.assertTrue(e1 not in items) items.discard(e2) self.assertTrue(e2 not in items)
def test_minimal_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] h_se.pos.x -= 20 # h.se.{x,y} == -10 h_se.pos.y -= 20 assert h_se.pos.x == h_se.pos.y == -10 box.request_update() canvas.update() self.assertEqual(10, h_se.pos.x) # h_se changed above, should be 10 self.assertEqual(10, h_se.pos.y) self.assertEqual(10, h_ne.pos.x) self.assertEqual(10, h_sw.pos.y)
class AspectTestCase(unittest.TestCase): """ Test aspects for items. """ def setUp(self): self.canvas = Canvas() self.view = View(self.canvas) def test_selection_select(self): """ Test the Selection role methods """ view = self.view item = Item() self.canvas.add(item) selection = Selection(item, view) assert item not in view.selected_items selection.select() assert item in view.selected_items assert item is view.focused_item selection.unselect() assert item not in view.selected_items assert None is view.focused_item def test_selection_move(self): """ Test the Selection role methods """ view = self.view item = Item() self.canvas.add(item) inmotion = InMotion(item, view) self.assertEquals((1, 0, 0, 1, 0, 0), tuple(item.matrix)) inmotion.start_move((0, 0)) inmotion.move((12, 26)) self.assertEquals((1, 0, 0, 1, 12, 26), tuple(item.matrix))
class AspectTestCase(unittest.TestCase): """ Test aspects for items. """ def setUp(self): self.canvas = Canvas() self.view = View(self.canvas) def test_selection_select(self): """ Test the Selection role methods """ view = self.view item = Item() self.canvas.add(item) selection = Selection(item, view) assert item not in view.selected_items selection.select() assert item in view.selected_items assert item is view.focused_item selection.unselect() assert item not in view.selected_items assert None is view.focused_item def test_selection_move(self): """ Test the Selection role methods """ view = self.view item = Item() self.canvas.add(item) inmotion = InMotion(item, view) self.assertEqual((1, 0, 0, 1, 0, 0), tuple(item.matrix)) inmotion.start_move((0, 0)) inmotion.move((12, 26)) self.assertEqual((1, 0, 0, 1, 12, 26), tuple(item.matrix))
def test_orthogonal_line_undo(self): """Test orthogonal line undo """ canvas = Canvas() line = Line() canvas.add(line) segment = Segment(line, None) segment.split_segment(0) # start with no orthogonal constraints assert len(canvas.solver._constraints) == 0 line.orthogonal = True # check orthogonal constraints self.assertEquals(2, len(canvas.solver._constraints)) self.assertEquals(3, len(line.handles())) undo() self.assertFalse(line.orthogonal) self.assertEquals(0, len(canvas.solver._constraints)) self.assertEquals(2, len(line.handles()))
def test_orthogonal_line_undo(self): """Test orthogonal line undo """ canvas = Canvas() line = Line() canvas.add(line) segment = Segment(line, None) segment.split_segment(0) # start with no orthogonal constraints assert len(canvas.solver._constraints) == 0 line.orthogonal = True # check orthogonal constraints self.assertEqual(2, len(canvas.solver._constraints)) self.assertEqual(3, len(line.handles())) undo() self.assertFalse(line.orthogonal) self.assertEqual(0, len(canvas.solver._constraints)) self.assertEqual(2, len(line.handles()))
def test_resize_se(self): """ Test resizing of element by dragging it SE handle. """ canvas = Canvas() box = Box() handles = box.handles() canvas.add(box) h_nw, h_ne, h_se, h_sw = handles assert h_nw is handles[NW] assert h_ne is handles[NE] assert h_sw is handles[SW] assert h_se is handles[SE] # to see how many solver was called: # GAPHAS_TEST_COUNT=3 nosetests -s --with-prof --profile-restrict=gaphas gaphas/tests/test_element.py | grep -e '\<solve\>' -e dirty count = getenv('GAPHAS_TEST_COUNT') if count: count = int(count) else: count = 1 for i in range(count): h_se.pos.x += 100 # h.se.{x,y} = 10, now h_se.pos.y += 100 box.request_update() canvas.update() self.assertEquals(110 * count, h_se.pos.x) # h_se changed above, should remain the same self.assertEquals(110 * count, float(h_se.pos.y)) self.assertEquals(110 * count, float(h_ne.pos.x)) self.assertEquals(110 * count, float(h_sw.pos.y))
def test_update_matrices(): """Test updating of matrices""" c = Canvas() i = Box() ii = Box() c.add(i) c.add(ii, i) i.matrix = (1.0, 0.0, 0.0, 1.0, 5.0, 0.0) ii.matrix = (1.0, 0.0, 0.0, 1.0, 0.0, 8.0) updated = c.update_matrices([i]) assert i._matrix_i2c == cairo.Matrix(1, 0, 0, 1, 5, 0) assert ii._matrix_i2c == cairo.Matrix(1, 0, 0, 1, 5, 8)
def test_update_matrices(self): """Test updating of matrices""" c = Canvas() i = Box() ii = Box() c.add(i) c.add(ii, i) i.matrix = (1.0, 0.0, 0.0, 1.0, 5.0, 0.0) ii.matrix = (1.0, 0.0, 0.0, 1.0, 0.0, 8.0) updated = c.update_matrices([i]) self.assertEquals(i._matrix_i2c, cairo.Matrix(1, 0, 0, 1, 5, 0)) self.assertEquals(ii._matrix_i2c, cairo.Matrix(1, 0, 0, 1, 5, 8))
class SimpleCanvas(object): """Creates a test canvas object. Adds a view, canvas, and handle connection tool to a test case. Two boxes and a line are added to the canvas as well. """ def __init__(self): self.canvas = Canvas() self.box1 = Box() self.canvas.add(self.box1) self.box1.matrix.translate(100, 50) self.box1.width = 40 self.box1.height = 40 self.box1.request_update() self.box2 = Box() self.canvas.add(self.box2) self.box2.matrix.translate(100, 150) self.box2.width = 50 self.box2.height = 50 self.box2.request_update() self.line = Line() self.head = self.line.handles()[0] self.tail = self.line.handles()[-1] self.tail.pos = 100, 100 self.canvas.add(self.line) self.canvas.update_now() self.view = GtkView() self.view.canvas = self.canvas self.win = Gtk.Window() self.win.add(self.view) self.view.show() self.view.update() self.win.show() self.tool = ConnectHandleTool(self.view)
def test_scroll_adjustments_signal(self): sc = Gtk.ScrolledWindow() view = GtkView(Canvas()) sc.add(view) assert view.hadjustment assert view.vadjustment assert view.hadjustment.get_value() == 0.0 assert view.hadjustment.get_lower() == 0.0 assert view.hadjustment.get_upper() == 1.0 assert view.hadjustment.get_step_increment() == 0.0 assert view.hadjustment.get_page_increment() == 1.0 assert view.hadjustment.get_page_size() == 1.0 assert view.vadjustment.get_value() == 0.0 assert view.vadjustment.get_lower() == 0.0 assert view.vadjustment.get_upper() == 1.0 assert view.vadjustment.get_step_increment() == 0.0 assert view.vadjustment.get_page_increment() == 1.0 assert view.vadjustment.get_page_size() == 1.0
class SimpleCanvas: """Creates a test canvas object. Adds a view, canvas, and handle connection tool to a test case. Two boxes and a line are added to the canvas as well. """ def __init__(self): self.canvas = Canvas() self.box1 = Box() self.canvas.add(self.box1) self.box1.matrix.translate(100, 50) self.box1.width = 40 self.box1.height = 40 self.box1.request_update() self.box2 = Box() self.canvas.add(self.box2) self.box2.matrix.translate(100, 150) self.box2.width = 50 self.box2.height = 50 self.box2.request_update() self.line = Line() self.head = self.line.handles()[0] self.tail = self.line.handles()[-1] self.tail.pos = 100, 100 self.canvas.add(self.line) self.canvas.update_now() self.view = GtkView() self.view.canvas = self.canvas self.win = Gtk.Window() self.win.add(self.view) self.view.show() self.view.update() self.win.show() self.tool = ConnectHandleTool(self.view)
def test_pickle_connect(self): """ Persist a connection. """ canvas = Canvas() box = Box() canvas.add(box) box2 = Box() canvas.add(box2, parent=box) line = Line() line.handles()[0].visible = False line.handles()[0].connected_to = box line.handles()[0].disconnect = my_disconnect() line.handles()[0].connection_data = 1 canvas.add(line) pickled = pickle.dumps(canvas) c2 = pickle.loads(pickled) assert type(canvas._tree.nodes[0]) is Box assert type(canvas._tree.nodes[1]) is Box assert type(canvas._tree.nodes[2]) is Line assert c2.solver line2 = c2._tree.nodes[2] h = line2.handles()[0] assert h.visible == False assert h.connected_to is c2._tree.nodes[0] # connection_data and disconnect have not been persisted assert h.connection_data == 1, h.connection_data assert h.disconnect, h.disconnect assert callable(h.disconnect) assert h.disconnect() is None, h.disconnect()
def test_disconnect_item_with_constraint(self): b1 = Box() b2 = Box() l = Line() c = Canvas() c.add(b1) c.add(b2) c.add(l) cons = b1.ports()[0].constraint(c, l, l.handles()[0], b1) c.connect_item(l, l.handles()[0], b1, b1.ports()[0], constraint=cons) assert count(c.get_connections(handle=l.handles()[0])) == 1 ncons = len(c.solver.constraints) assert ncons == 5 c.disconnect_item(l, l.handles()[0]) assert count(c.get_connections(handle=l.handles()[0])) == 0 assert len(c.solver.constraints) == 4