More gaphor.misc fixes

This commit is contained in:
Arjan Molenaar 2018-11-23 22:44:52 +01:00
parent 2853252f6d
commit 286156bb3a
6 changed files with 28 additions and 25 deletions

View File

@ -1,6 +1,6 @@
# vim:sw=4:et: # vim:sw=4:et:
"""This module contains some helpers that can be used to execute generator """This module contains some helpers that can be used to execute generator
functions in the GObject main loop. functions in the GLib main loop.
This module provided the following classes: This module provided the following classes:
GIdleThread - Thread like behavior for generators in a main loop GIdleThread - Thread like behavior for generators in a main loop
@ -18,7 +18,7 @@ from builtins import next
from builtins import range from builtins import range
import types import types
import sys import sys
from gi.repository import GLib, GObject from gi.repository import GLib
import time import time
import traceback import traceback
@ -86,7 +86,7 @@ class GIdleThread(object):
"""Force the generator to stop running. """Force the generator to stop running.
""" """
if self.is_alive(): if self.is_alive():
GObject.source_remove(self._idle_id) GLib.source_remove(self._idle_id)
self._idle_id = 0 self._idle_id = 0
def is_alive(self): def is_alive(self):

View File

@ -36,26 +36,26 @@ class GenUmlTestCase(unittest.TestCase):
GENERATED = """# This file is generated by build_uml.py. DO NOT EDIT! GENERATED = """# This file is generated by build_uml.py. DO NOT EDIT!
from properties import association, attribute, enumeration, derived, derivedunion, redefine from gaphor.UML.properties import association, attribute, enumeration, derived, derivedunion, redefine
# class 'ValSpec' has been stereotyped as 'SimpleAttribute' # class 'ValSpec' has been stereotyped as 'SimpleAttribute'
# class 'ShouldNotShowUp' has been stereotyped as 'SimpleAttribute' too # class 'ShouldNotShowUp' has been stereotyped as 'SimpleAttribute' too
class C(object): pass
class D(C): pass
class Element(object): pass class Element(object): pass
class SubClass(Element): pass class SubClass(Element): pass
C.attr = attribute('attr', 8cb780ba-3f11-11de-9595-00224128e79d, default=8cb7fd1a-3f11-11de-9595-00224128e79d, upper=8cb7df60-3f11-11de-9595-00224128e79d, lower=8cb7c11a-3f11-11de-9595-00224128e79d) class C(object): pass
# 'SubClass.value' is a simple attribute class D(C): pass
SubClass.value = attribute('value', str, lower=f9124094-3f14-11de-9595-00224128e79d) C.attr = attribute('attr', 8cb780ba-3f11-11de-9595-00224128e79d, default=8cb7fd1a-3f11-11de-9595-00224128e79d, lower=8cb7c11a-3f11-11de-9595-00224128e79d, upper=8cb7df60-3f11-11de-9595-00224128e79d)
C.name1 = association('name1', SubClass, lower=602cb072-3bcb-11de-ac7f-00224128e79d, opposite='name2') C.name1 = association('name1', SubClass, lower=602cb072-3bcb-11de-ac7f-00224128e79d, opposite='name2')
SubClass.name2 = association('name2', C, lower=602d56c6-3bcb-11de-ac7f-00224128e79d, opposite='name1') SubClass.name2 = association('name2', C, lower=602d56c6-3bcb-11de-ac7f-00224128e79d, opposite='name1')
C.base = association('base', SubClass, lower=e053585e-3bcc-11de-aa0c-00224128e79d, opposite='abstract') C.base = association('base', SubClass, lower=e053585e-3bcc-11de-aa0c-00224128e79d, opposite='abstract')
D.name3 = association('name3', SubClass, lower=1af287dc-3bcd-11de-aa0c-00224128e79d, opposite='name4')
D.subbase = association('subbase', SubClass, lower=f8d56502-3bcc-11de-aa0c-00224128e79d, opposite='concrete') D.subbase = association('subbase', SubClass, lower=f8d56502-3bcc-11de-aa0c-00224128e79d, opposite='concrete')
SubClass.concrete = association('concrete', D, lower=f8d5c998-3bcc-11de-aa0c-00224128e79d, upper=1665b18a-3bcd-11de-aa0c-00224128e79d, opposite='subbase') SubClass.concrete = association('concrete', D, lower=f8d5c998-3bcc-11de-aa0c-00224128e79d, upper=1665b18a-3bcd-11de-aa0c-00224128e79d, opposite='subbase')
D.name3 = association('name3', SubClass, lower=1af287dc-3bcd-11de-aa0c-00224128e79d, opposite='name4')
SubClass.abstract = derivedunion('abstract', C, e053abd8-3bcc-11de-aa0c-00224128e79d, f48f64a2-3bcc-11de-aa0c-00224128e79d, SubClass.concrete) SubClass.abstract = derivedunion('abstract', C, e053abd8-3bcc-11de-aa0c-00224128e79d, f48f64a2-3bcc-11de-aa0c-00224128e79d, SubClass.concrete)
SubClass.name4 = redefine(SubClass, 'name4', D, name2) SubClass.name4 = redefine(SubClass, 'name4', D, name2)
""" """
# # 'SubClass.value' is a simple attribute
# SubClass.value = attribute('value', str, lower=f9124094-3f14-11de-9595-00224128e79d)
# vim:sw=4:et:ai # vim:sw=4:et:ai

View File

@ -38,6 +38,7 @@ class UndoRedoBugTestCase(TestCase):
self.remove_attribute() self.remove_attribute()
assert len(self.class_.ownedAttribute) == 0 assert len(self.class_.ownedAttribute) == 0
assert self.attribute.namespace is None assert self.attribute.namespace is None
assert self.undo_manager.can_undo()
self.undo_manager.undo_transaction() self.undo_manager.undo_transaction()

View File

@ -5,7 +5,7 @@ Test GitHub issue #4. Diagram could not be loaded due to JuggleError
import os import os
import pkg_resources import pkg_resources
from gi.repository import GObject from gi.repository import GLib
from gi.repository import Gtk from gi.repository import Gtk
from gaphor.storage.storage import load from gaphor.storage.storage import load
@ -45,7 +45,7 @@ class CyclicDiagramTestCase(TestCase):
finally: finally:
Gtk.main_quit() Gtk.main_quit()
assert GObject.timeout_add(1, handler) > 0 assert GLib.timeout_add(1, handler) > 0
Gtk.main() Gtk.main()

View File

@ -13,11 +13,13 @@ class UndoTest(TestCase):
factory = self.element_factory factory = self.element_factory
undo_manager = self.get_service('undo_manager') undo_manager = self.get_service('undo_manager')
self.assertEqual(0, len(self.diagram.canvas.solver.constraints))
ci1 = self.create(items.ClassItem, UML.Class) ci1 = self.create(items.ClassItem, UML.Class)
self.assertEqual(6, len(self.diagram.canvas.solver.constraints)) self.assertEqual(2, len(self.diagram.canvas.solver.constraints))
ci2 = self.create(items.ClassItem, UML.Class) ci2 = self.create(items.ClassItem, UML.Class)
self.assertEqual(12, len(self.diagram.canvas.solver.constraints)) self.assertEqual(4, len(self.diagram.canvas.solver.constraints))
a = self.create(items.AssociationItem) a = self.create(items.AssociationItem)
@ -26,7 +28,7 @@ class UndoTest(TestCase):
# Diagram, Association, 2x Class, Property, LiteralSpecification # Diagram, Association, 2x Class, Property, LiteralSpecification
self.assertEqual(6, len(factory.lselect())) self.assertEqual(6, len(factory.lselect()))
self.assertEqual(14, len(self.diagram.canvas.solver.constraints)) self.assertEqual(6, len(self.diagram.canvas.solver.constraints))
@transactional @transactional
def delete_class(): def delete_class():
@ -46,11 +48,11 @@ class UndoTest(TestCase):
# Diagram, Class # Diagram, Class
#self.assertEqual(2, len(factory.lselect()), factory.lselect()) #self.assertEqual(2, len(factory.lselect()), factory.lselect())
self.assertEqual(7, len(self.diagram.canvas.solver.constraints)) self.assertEqual(3, len(self.diagram.canvas.solver.constraints))
undo_manager.undo_transaction() undo_manager.undo_transaction()
self.assertEqual(14, len(self.diagram.canvas.solver.constraints)) self.assertEqual(6, len(self.diagram.canvas.solver.constraints))
self.assertEqual(ci1, self.get_connected(a.head)) self.assertEqual(ci1, self.get_connected(a.head))
self.assertEqual(ci2, self.get_connected(a.tail)) self.assertEqual(ci2, self.get_connected(a.tail))

View File

@ -282,16 +282,16 @@ def parse_association_tags(appliedStereotypes):
for slot in stereotype.slot or []: for slot in stereotype.slot or []:
#msg('scanning %s = %s' % (slot.definingFeature.name, slot.value.value)) msg('scanning %s = %s' % (slot.definingFeature.name, slot.value.value))
if slot.definingFeature.name == 'subsets': if slot.definingFeature.name == 'subsets':
value = slot.value value = slot.value.value
# remove all whitespaces and stuff # remove all whitespaces and stuff
value = value.replace(' ', '').replace('\n', '').replace('\r', '') value = value.replace(' ', '').replace('\n', '').replace('\r', '')
subsets = value.split(',') subsets = value.split(',')
if slot.definingFeature.name == 'redefines': if slot.definingFeature.name == 'redefines':
value = slot.value value = slot.value.value
# remove all whitespaces and stuff # remove all whitespaces and stuff
redefines = value.replace(' ', '').replace('\n', '').replace('\r', '') redefines = value.replace(' ', '').replace('\n', '').replace('\r', '')