-
-
Notifications
You must be signed in to change notification settings - Fork 216
Allow spaces in string attribute value #3448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow spaces in string attribute value #3448
Conversation
Regression test$ git show
commit fcf9d53d39651dc76ec8f7661662196cbdd39067
Author: Emanuele Zarfati <zarfati.tecno@gmail.com>
Date: Fri Aug 16 21:55:12 2024 +0200
Do not generate quoted quoted `default_value` Click to show test results
$ poetry run pytest
============================================= test session starts ==============================================
platform linux -- Python 3.12.5, pytest-8.3.2, pluggy-1.5.0
Using --randomly-seed=2778894578
rootdir: *
configfile: pyproject.toml
testpaths: gaphor, tests, docs
plugins: randomly-3.15.0, cov-5.0.0, archon-0.0.6, xdoctest-1.1.6, mock-3.14.0, hypothesis-6.111.0
collected 2019 items
gaphor/action.py . [ 0%]
gaphor/core/modeling/collection.py . [ 0%]
gaphor/core/modeling/element.py . [ 0%]
gaphor/storage/storage.py . [ 0%]
gaphor/storage/upgrade_canvasitem.py . [ 0%]
gaphor/transaction.py . [ 0%]
gaphor/UML/interactions/tests/test_message.py .... [ 0%]
gaphor/UML/classes/tests/test_associationconnect.py .x............. [ 1%]
gaphor/core/styling/tests/test_declarations.py ............................ [ 2%]
gaphor/diagram/tools/tests/test_txtool.py . [ 2%]
gaphor/core/styling/tests/test_compiler.py .......................................... [ 4%]
gaphor/UML/actions/tests/test_flow.py .... [ 4%]
gaphor/diagram/tests/test_instanteditors.py ... [ 5%]
gaphor/ui/tests/test_lifecycle.py .... [ 5%]
gaphor/core/styling/tests/test_inherit.py .. [ 5%]
tests/test_elements_have_owner.py .... [ 5%]
gaphor/SysML/tests/test_diagramlabel.py .. [ 5%]
gaphor/diagram/tests/test_merge.py . [ 5%]
tests/test_auto_layouting.py . [ 5%]
gaphor/UML/usecases/tests/test_include.py .... [ 5%]
tests/test_plugins.py . [ 6%]
gaphor/UML/usecases/tests/test_actor.py ... [ 6%]
gaphor/diagram/tests/test_copypaste_link.py .......... [ 6%]
gaphor/UML/tests/test_diagramitems.py .................................................................. [ 9%]
....................................................................................... [ 14%]
gaphor/ui/tests/test_main.py .. [ 14%]
gaphor/ui/tests/test_actiongroup.py ........... [ 14%]
gaphor/UML/interactions/tests/test_drop.py . [ 14%]
gaphor/UML/classes/tests/test_associationpropertypages.py ... [ 15%]
gaphor/UML/classes/tests/test_interface.py .. [ 15%]
gaphor/UML/classes/tests/test_classespropertypages.py .......... [ 15%]
gaphor/C4Model/tests/test_grouping.py .... [ 15%]
gaphor/tests/test_application.py .... [ 16%]
gaphor/diagram/general/tests/test_generalpropertypages.py ... [ 16%]
gaphor/ui/tests/test_notifier.py ... [ 16%]
gaphor/tests/test_entrypoint.py ... [ 16%]
gaphor/UML/interactions/tests/test_executionspecification.py ........... [ 17%]
gaphor/UML/tests/test_group.py .......... [ 17%]
gaphor/UML/classes/tests/test_datatype_connect.py . [ 17%]
gaphor/ui/tests/test_modelchanged.py .. [ 17%]
gaphor/UML/tests/test_activity.py ........................... [ 19%]
gaphor/UML/profiles/tests/test_copypaste.py .. [ 19%]
gaphor/SysML/blocks/tests/test_block.py .. [ 19%]
gaphor/core/styling/tests/test_cascading.py ........... [ 19%]
tests/test_session_recovery.py .................. [ 20%]
gaphor/SysML/blocks/tests/test_group.py ... [ 20%]
gaphor/UML/actions/tests/test_grouping.py ...... [ 21%]
gaphor/SysML/requirements/tests/test_connectors.py ....... [ 21%]
gaphor/ui/tests/test_elementeditor.py ... [ 21%]
tests/test_undo.py ................ [ 22%]
gaphor/UML/actions/tests/test_partitionpage.py ... [ 22%]
gaphor/diagram/general/tests/test_generaleditors.py . [ 22%]
gaphor/UML/profiles/tests/test_extensionconnect.py ....... [ 22%]
gaphor/diagram/tests/test_group.py ........ [ 23%]
gaphor/C4Model/tests/test_propertypages.py .. [ 23%]
tests/test_composite_association.py . [ 23%]
gaphor/UML/actions/tests/test_activitypropertypage.py ................ [ 24%]
gaphor/ui/tests/test_statuswindow.py . [ 24%]
gaphor/UML/actions/tests/test_pin.py . [ 24%]
gaphor/tests/test_main.py ...... [ 24%]
gaphor/UML/deployments/tests/test_copypaste.py . [ 24%]
gaphor/UML/tests/test_uml2_overrides.py .... [ 24%]
gaphor/plugins/console/tests/test_consolewindow.py . [ 25%]
tests/test_action_issue.py . [ 25%]
gaphor/services/tests/test_modelinglanguage.py .... [ 25%]
gaphor/ui/tests/test_treemodel.py ................. [ 26%]
gaphor/core/modeling/tests/test_presentation.py .......... [ 26%]
gaphor/UML/tests/test_drop.py ....... [ 26%]
gaphor/UML/tests/test_sanitizerservice.py ............. [ 27%]
gaphor/core/modeling/tests/test_collection.py .............. [ 28%]
gaphor/plugins/errorreports/tests/test_errorreport.py ... [ 28%]
gaphor/ui/tests/test_filemanager.py .....s... [ 28%]
gaphor/UML/classes/tests/test_generalizationconnect.py ........ [ 29%]
tests/test_model_consistency.py . [ 29%]
tests/test_presentations.py ................. [ 30%]
gaphor/extensions/tests/test_sphinx.py .. [ 30%]
gaphor/UML/classes/tests/test_class.py ... [ 30%]
gaphor/storage/tests/test_storage_message_item_upgrade.py . [ 30%]
tests/test_placement_tools.py .......................................................................... [ 34%]
................................................................. [ 37%]
gaphor/codegen/tests/test_coder.py ....................... [ 38%]
gaphor/UML/usecases/tests/test_extend.py .... [ 38%]
gaphor/UML/actions/tests/test_flowconnect.py ........................................ [ 40%]
gaphor/UML/deployments/tests/test_grouping.py ....... [ 41%]
gaphor/UML/actions/tests/test_forknode.py ... [ 41%]
gaphor/UML/profiles/tests/test_stereotypepage.py .. [ 41%]
gaphor/tests/test_action.py .... [ 41%]
gaphor/tests/test_i18n.py . [ 41%]
gaphor/storage/tests/test_recovery_recorder.py ................ [ 42%]
gaphor/UML/tests/test_umlfmt.py ..................................... [ 44%]
gaphor/ui/tests/test_treesearch.py ..... [ 44%]
gaphor/tests/test_settings.py .. [ 44%]
tests/test_multiple_associations.py .. [ 44%]
gaphor/diagram/tools/tests/test_handlemove.py ... [ 44%]
gaphor/storage/tests/test_mergeconflict.py . [ 44%]
gaphor/diagram/tests/test_presentation.py ........ [ 45%]
gaphor/UML/interactions/tests/test_messageconnect.py ................... [ 46%]
tests/test_diagramexport.py .... [ 46%]
gaphor/ui/tests/test_selftest.py . [ 46%]
gaphor/UML/states/tests/test_transition_connect.py ........ [ 46%]
gaphor/UML/actions/tests/test_copypaste.py ... [ 46%]
gaphor/diagram/tools/tests/test_shortcut.py .. [ 47%]
tests/test_package_removal.py .. [ 47%]
gaphor/SysML/tests/test_sysml.py ....... [ 47%]
gaphor/core/modeling/tests/test_diagram_style.py .... [ 47%]
gaphor/UML/actions/tests/test_action.py .. [ 47%]
gaphor/UML/classes/tests/test_classeseditors.py . [ 47%]
gaphor/services/tests/test_componentregistry.py .. [ 47%]
gaphor/plugins/console/tests/test_docstring_formatting.py ... [ 48%]
gaphor/storage/tests/test_group.py . [ 48%]
gaphor/UML/actions/tests/test_actionspropertypages.py ....... [ 48%]
gaphor/UML/profiles/tests/test_stereotypepropertypages.py ..... [ 48%]
gaphor/ui/tests/test_handletool.py ...... [ 48%]
gaphor/UML/states/tests/test_transition.py . [ 49%]
tests/test_models_up_to_date.py ..... [ 49%]
gaphor/ui/modelmerge/tests/test_organize_uml.py .......... [ 49%]
tests/test_remove_unused_elements.py .. [ 49%]
gaphor/UML/tests/test_interactions.py .... [ 50%]
gaphor/ui/tests/test_recentfiles.py ... [ 50%]
gaphor/diagram/tools/tests/test_tool_set.py ... [ 50%]
gaphor/UML/actions/tests/test_partition.py ... [ 50%]
gaphor/UML/interactions/tests/test_interactionspropertypages.py .. [ 50%]
gaphor/storage/tests/test_parser.py .... [ 50%]
gaphor/plugins/autolayout/tests/test_pydot.py ......... [ 51%]
gaphor/UML/states/tests/test_propertypages.py ..... [ 51%]
gaphor/diagram/tests/test_segment.py . [ 51%]
gaphor/UML/interactions/tests/test_ordering.py .. [ 51%]
gaphor/tests/test_transaction.py ........ [ 52%]
gaphor/tests/test_raises.py .... [ 52%]
gaphor/C4Model/tests/test_modelinglanguage.py ...... [ 52%]
gaphor/UML/classes/tests/test_enumerationpropertypages.py .. [ 52%]
tests/test_comment_line_placement.py . [ 52%]
tests/test_unioncache_in_derived_response.py . [ 52%]
gaphor/SysML/blocks/tests/test_proxy_port.py .... [ 52%]
gaphor/UML/classes/tests/test_interfacerealizationconnect.py ... [ 53%]
gaphor/diagram/tests/test_shapes.py .................. [ 53%]
gaphor/UML/classes/tests/test_association.py ........ [ 54%]
gaphor/ui/tests/test_filedialog.py ..... [ 54%]
gaphor/core/modeling/tests/test_elementdispatcher.py ............... [ 55%]
gaphor/diagram/tests/test_text.py ....................... [ 56%]
gaphor/core/modeling/tests/test_element.py .. [ 56%]
gaphor/core/modeling/tests/test_modelinglanguage.py ... [ 56%]
gaphor/ui/tests/test_toolbox.py ...... [ 57%]
gaphor/SysML/tests/test_propertypages.py .................... [ 58%]
gaphor/services/tests/test_properties.py ... [ 58%]
gaphor/UML/classes/tests/test_containmentconnect.py ........ [ 58%]
gaphor/UML/states/tests/test_states.py ..... [ 58%]
gaphor/UML/deployments/tests/test_connect.py ................ [ 59%]
gaphor/core/changeset/tests/test_apply.py ..................... [ 60%]
gaphor/SysML/allocations/tests/test_allocate_relationship.py ......................... [ 61%]
gaphor/UML/states/tests/test_group.py ........ [ 62%]
gaphor/diagram/tests/test_copypaste.py .. [ 62%]
gaphor/core/modeling/tests/test_diagram.py .......... [ 62%]
gaphor/plugins/console/tests/test_console.py ..... [ 63%]
gaphor/UML/tests/test_iconname.py . [ 63%]
tests/test_load_model.py . [ 63%]
gaphor/storage/tests/test_storage_upgrades.py ............... [ 63%]
gaphor/SysML/tests/test_drop.py .... [ 64%]
gaphor/UML/profiles/tests/test_metaclasspropertypage.py .. [ 64%]
gaphor/core/changeset/tests/test_compare.py .................... [ 65%]
tests/test_properties.py ............................................................................... [ 69%]
............ [ 69%]
gaphor/diagram/tests/test_propertypages.py ....... [ 70%]
gaphor/diagram/tests/test_styling.py . [ 70%]
gaphor/tests/test_babel.py . [ 70%]
gaphor/ui/tests/test_copyservice.py .. [ 70%]
gaphor/SysML/blocks/tests/test_connectors.py ........ [ 70%]
gaphor/UML/tests/test_state_machine.py ............................................................ [ 73%]
gaphor/UML/classes/tests/test_dependencyconnect.py .......... [ 74%]
gaphor/diagram/tests/test_export.py ..... [ 74%]
gaphor/ui/installschemas/tests/test_installschemas.py . [ 74%]
gaphor/UML/classes/tests/test_dependencypropertypages.py .. [ 74%]
gaphor/ui/modelmerge/tests/test_modelmerge.py . [ 74%]
gaphor/UML/tests/test_recipes.py ............... [ 75%]
gaphor/diagram/general/tests/test_comment.py ............ [ 75%]
gaphor/storage/tests/test_xmlwriter.py ..... [ 76%]
gaphor/services/tests/test_undo_presentation.py ..................... [ 77%]
gaphor/UML/actions/tests/test_drop.py ....... [ 77%]
gaphor/UML/actions/tests/test_activitynodes.py ..... [ 77%]
gaphor/tests/test_version.py . [ 77%]
gaphor/UML/profiles/tests/test_packageimportconnect.py ... [ 78%]
gaphor/ui/tests/test_menufragment.py . [ 78%]
gaphor/ui/tests/test_help.py ... [ 78%]
gaphor/UML/usecases/tests/test_connect.py .. [ 78%]
gaphor/core/styling/tests/test_css.py ..................................................... [ 80%]
gaphor/core/modeling/tests/test_literal_eval.py ...... [ 81%]
gaphor/ui/modelmerge/tests/test_organize.py ................. [ 82%]
gaphor/UML/classes/tests/test_copypaste.py .......... [ 82%]
gaphor/UML/interactions/tests/test_group.py . [ 82%]
tests/test_architecture.py ........ [ 83%]
gaphor/SysML/tests/test_diagramitems.py ................................. [ 84%]
gaphor/UML/deployments/tests/test_connector.py .. [ 84%]
gaphor/UML/interactions/tests/test_copypaste.py .. [ 84%]
gaphor/SysML/tests/test_sysmlfmt.py ...... [ 85%]
gaphor/ui/tests/test_modelbrowser.py ...................... [ 86%]
gaphor/UML/usecases/tests/test_grouping.py ... [ 86%]
gaphor/diagram/tests/test_copypaste_full.py ........ [ 86%]
gaphor/core/modeling/tests/test_elementfactory.py .............. [ 87%]
gaphor/diagram/tests/test_copypaste_grouping.py ... [ 87%]
gaphor/ui/tests/test_diagrampage.py .... [ 87%]
gaphor/UML/actions/tests/test_actionseditors.py ... [ 88%]
gaphor/storage/tests/test_storage_uml_2_5_upgrade.py ...... [ 88%]
gaphor/diagram/general/tests/test_simpleitem.py ... [ 88%]
gaphor/storage/tests/test_storage_c4_upgrades.py . [ 88%]
gaphor/diagram/tests/test_iconname.py . [ 88%]
gaphor/ui/tests/test_greeter.py .. [ 88%]
gaphor/UML/tests/test_uml2.py ........................... [ 89%]
gaphor/storage/tests/test_storage.py ............... [ 90%]
tests/test_issue_gaphas.py . [ 90%]
gaphor/UML/states/tests/test_pseudostates.py ............ [ 91%]
gaphor/UML/states/tests/test_copypaste.py .. [ 91%]
gaphor/UML/tests/test_copypaste.py ... [ 91%]
gaphor/UML/classes/tests/test_realizationconnect.py ..... [ 91%]
gaphor/services/tests/test_undomanager.py .................. [ 92%]
gaphor/SysML/tests/test_diagramtype.py . [ 92%]
gaphor/ui/tests/test_macosshim.py s [ 92%]
gaphor/UML/actions/tests/test_objectnode.py ... [ 93%]
gaphor/UML/actions/tests/test_callbehaviouraction.py .. [ 93%]
gaphor/services/tests/test_moduleloader.py . [ 93%]
gaphor/UML/states/tests/test_drop.py ... [ 93%]
gaphor/UML/actions/tests/test_pinconnect.py ....... [ 93%]
gaphor/core/modeling/tests/test_properties.py ............................... [ 95%]
gaphor/UML/tests/test_umllex.py ...................................... [ 97%]
gaphor/UML/profiles/tests/test_classifier_stereotypes.py ....... [ 97%]
gaphor/extensions/tests/test_ipython.py . [ 97%]
gaphor/storage/tests/test_recovery_eventlog.py .....x. [ 97%]
gaphor/storage/tests/test_loading.py ...... [ 98%]
gaphor/UML/classes/tests/test_interfaceconnect.py ....... [ 98%]
gaphor/services/tests/test_undo_diagram.py .. [ 98%]
gaphor/diagram/tools/tests/test_dropzone.py .. [ 98%]
gaphor/core/modeling/tests/test_style_attributes.py .............. [ 99%]
gaphor/core/tests/test_eventmanager.py .... [ 99%]
gaphor/ui/tests/test_mainwindow.py ..s.s.... [100%]
============================ 2013 passed, 4 skipped, 2 xfailed in 154.81s (0:02:34) ============================ |
@itafraze This is some really nice regex wizardry 😃 . I wonder if the default value should retain the quotes or if they should be removed. Now, strings will contain open and closing quotes after being formatted and parsed again. |
@amolenaar I didn't do everything myself. I had to look better into the regex and adapt what I found online (thank you www).
Could you please elaborate? I see the need to consistenly handle this information among UI,
So, in principle, single quotes should not enclose a string, and escaping double quotes is not even considered (unless it is considered a feature of the character set, I suppose). UINow, it does not really care about the specification:
|
<Property id="...">
...
<defaultValue>
<val>"Some"</val>
</defaultValue>
<name>
<val>attr</val>
</name>
<typeValue>
<val>String</val>
</typeValue>
</Property> |
<Property id="...">
...
<defaultValue>
<val>'Some'</val>
</defaultValue>
<name>
<val>attr</val>
</name>
<typeValue>
<val>String</val>
</typeValue>
</Property> |
<Property id="...">
...
<defaultValue>
<val>Some</val>
</defaultValue>
<name>
<val>attr</val>
</name>
<typeValue>
<val>String</val>
</typeValue>
</Property> |
<Property id="...">
...
<name>
<val>+ attr: String = "Some text"</val>
</name>
</Property> |
<Property id="...">
...
<name>
<val>+ attr: String = 'Some text'</val>
</name>
</Property> |
<Property id="...">
...
<name>
<val>+ attr: String = Some text</val>
</name>
</Property> |
With current PR only the bottom left and center classes are affected:
<Property id="...">
...
<defaultValue>
<val>"Some text"</val>
</defaultValue>
<name>
<val>attr</val>
</name>
<typeValue>
<val>String</val>
</typeValue>
</Property> |
<Property id="...">
...
<defaultValue>
<val>'Some text'</val>
</defaultValue>
<name>
<val>attr</val>
</name>
<typeValue>
<val>String</val>
</typeValue>
</Property> |
coder
Currently the above cause gaphor.codegen.coder
to fail in those instances with a space. An example is:
File "gaphor/codegen/coder.py", line 219, in variables
raise ValueError(
ValueError: + attr: String = "Some text": None can not be written; owner=Valid
Once only the top three classes are kept, gaphor.codegen.coder
outputs:
class Valid():
attr: _attribute[str] = _attribute("attr", str, default=""Some"")
class Invalid():
attr: _attribute[str] = _attribute("attr", str, default="'Some'")
class Invalid():
attr: _attribute[str] = _attribute("attr", str, default="Some")
With current PR, gaphor.codegen.coder
still fails due to the bottom right class. Once it is removed, the output Python code is:
class Valid():
attr: _attribute[str] = _attribute("attr", str, default="Some")
class Invalid():
attr: _attribute[str] = _attribute("attr", str, default='Some')
class Invalid():
attr: _attribute[str] = _attribute("attr", str, default="Some")
class Valid():
attr: _attribute[str] = _attribute("attr", str, default="Some text")
class Invalid():
attr: _attribute[str] = _attribute("attr", str, default='Some text')
Modify regex
gaphor/gaphor/UML/umllex.py
Line 36 in 6fee35e
to treat differently the
default
match in case the text is sorrounded by either"
or`
. In this latter case regexapplies (it should allow for escaped quotes between quotes.
Also, fixes the generation of code from the model. In the following snippet
coder.py
applies double quotes regardless ifa.defaultValue
is already quoted or not. In the former case the generated Python code is not valid.gaphor/gaphor/codegen/coder.py
Lines 307 to 308 in 62b2fa0
PR Checklist
PR Type
What is the current behavior?
Issue Number: Fixes #3432
See the issue for more information
What is the new behavior?
See the issue expected behavior.
Does this PR introduce a breaking change?
Other information