Skip to content

Refactor generate jsonmap - #271

Draft
tomkane-dls wants to merge 2 commits into
mainfrom
refactor-generate-jsonmap
Draft

tomkane-dls wants to merge 2 commits into
mainfrom
refactor-generate-jsonmap

Conversation

@tomkane-dls

@tomkane-dls tomkane-dls commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Refactor generate jsonmap

Kept generate_jsonmap.py at the top level, but split the internals into four files within jsonmap/: nodes.py, links.py, naming.py, crawl.py. Added dataclasses like WidgetLink and CrawlContext to group things a little more intuitively. Nearly all the changes are purely cosmetic, the code produces identical jsonmaps to what it did previously

Changes

nodes.py

  • renamed JsonMap -> ScreenNode
  • renamed _serialise_json_map -> serialise_node
  • removed the nested _check_default and refactred and replaced with field_default

links.py

  • widget loop generate_json_map now moved to extract_links
  • WidgetLink is now a dataclass (file, name, type, macros)
  • Widget type list now a StrEnum called WidgetType
  • contains helpers extract_file_text and is_bob
  • Path logic from _child_file_crawl now resolve_link_path and find_local_screen
  • exists rule for unfound files moved to assumed_exists

naming.py

  • _get_component_label renamed to find_techui_label and moved to jsonmap/naming.py; it now returns the label or None.
  • renamed _parse_display_name -> name_or_file_stem
  • renamed _fix_names_json_map -> fix_duplicate_names
  • removed _get_display_name - display-name order written out in crawl.

crawl.py

  • the internals of JsonMapGenerator.generate_json_map now in crawl
  • nested _child_file_crawl now in crawl_link and takes a WidgetLink.
  • using CrawlContext to pass between recursion steps
  • component lookup moved to CrawlContext.with_screen_component.

generate_jsonmap.py

  • JsonMapGenerator._current_service_name removed; the service name is passed down in CrawlContext
  • JsonMapGenerator.generate_json_map now builds a CrawlContext and calls crawl.

Tests

moved/updated:

  • test_serialise_json_map renamed to test_serialise_node and moved to tests/jsonmap/test_nodes.py.
  • test_parse_display_name_* renamed to test_name_or_file_stem_* and moved to tests/jsonmap/test_naming.py.
  • test_fix_names_json_map_recursive renamed to test_fix_duplicate_names_recursive and moved to tests/jsonmap/test_naming.py.
  • test_get_component_label* renamed to test_find_techui_label* and moved to tests/jsonmap/test_naming.py; the invalid-name tests expect None.
  • test_get_action_group* and test_get_nav_tabs* moved to tests/test_utils.py.
  • test_generate_json_map_get_macros and test_generate_json_map_other_exception patch techui_builder.jsonmap.links._get_action_group.
  • Naming mocks removed from test_generate_json_map, test_generate_json_map_embedded_screen, test_generate_json_map_nav_tabs, test_generate_json_map_get_macros and test_generate_json_map_other_exception.
  • _get_action_group patch removed from test_generate_json_map.
  • test_generate_json_map_embedded_screen expects display name "Z".
  • test_write_json_map patches techui_builder.generate_jsonmap.serialise_node.
  • tests/conftest.py uses ScreenNode from techui_builder.jsonmap.nodes.
  • tests/test_autofiller.py patches techui_builder.autofill.objectify.deannotate and lxml.etree.ElementTree.

new tests:

  • tests/test_utils.py: test_get_macros.
  • tests/jsonmap/test_nodes.py: test_field_default.
  • tests/jsonmap/test_links.py: test_extract_links, test_resolve_link_path, test_find_local_screen, test_assumed_exists.
  • tests/jsonmap/test_crawl.py: test_crawl, test_crawl_component_screen, test_crawl_link, test_with_screen_component.

@tomkane-dls
tomkane-dls marked this pull request as draft September 17, 2026 13:44
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.56710% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.61%. Comparing base (a0932ec) to head (2e1b295).

Files with missing lines Patch % Lines
src/techui_builder/jsonmap/links.py 98.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #271      +/-   ##
==========================================
+ Coverage   96.04%   96.61%   +0.56%     
==========================================
  Files          13       17       +4     
  Lines         986     1033      +47     
==========================================
+ Hits          947      998      +51     
+ Misses         39       35       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tomkane-dls
tomkane-dls requested review from OCopping and adedamola-sode and removed request for OCopping September 17, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants