@@ -26,66 +26,74 @@ class SpriteProvider:
2626 def resolve (self , value ):
2727 return f"https://sprites.example/{ value } .svg"
2828
29- styles = {"icons " : { "big bridge" : { "provider " : "sprite" , "value" : "bridge" } }}
29+ styles = {"icon_provider " : "sprite" , "icons " : { "big bridge" : "bridge" }}
3030
3131 with mock .patch .dict (ICON_PROVIDERS , {"sprite" : SpriteProvider ()}):
3232 resolved = resolve_marker_styles (styles )
3333
3434 assert resolved ["icons" ] == {"big bridge" : "https://sprites.example/bridge.svg" }
3535
3636
37- def test_resolves_phosphor_entry_to_cdn_url ():
38- styles = {"icons" : {"big bridge" : {"provider" : "phosphor" , "value" : "bridge" }}}
39-
40- assert resolve_marker_styles (styles )["icons" ] == {"big bridge" : PHOSPHOR_BRIDGE_URL }
41-
42-
43- def test_resolves_url_provider_entry_to_its_value ():
44- styles = {"icons" : {"container" : {"provider" : "url" , "value" : "https://e.example/c.svg" }}}
37+ def test_phosphor_provider_resolves_every_entry_in_the_table ():
38+ styles = {
39+ "icon_provider" : "phosphor" ,
40+ "icons" : {"big bridge" : "bridge" , "small bridge" : "footprints" },
41+ }
4542
46- assert resolve_marker_styles (styles )["icons" ] == {"container" : "https://e.example/c.svg" }
43+ assert resolve_marker_styles (styles )["icons" ] == {
44+ "big bridge" : PHOSPHOR_BRIDGE_URL ,
45+ "small bridge" : (
46+ "https://cdn.jsdelivr.net/npm/@phosphor-icons/core@2/assets/fill/footprints-fill.svg"
47+ ),
48+ }
4749
4850
49- def test_passes_plain_string_entry_through_unchanged ():
50- styles = {"icons" : {"container" : "https://e.example/c.svg" }}
51+ def test_url_provider_serves_entries_the_deployment_hosts_itself ():
52+ styles = {"icon_provider" : "url" , " icons" : {"container" : "https://e.example/c.svg" }}
5153
5254 assert resolve_marker_styles (styles )["icons" ] == {"container" : "https://e.example/c.svg" }
5355
5456
5557@pytest .mark .parametrize (
56- "entry " ,
58+ "styles " ,
5759 [
58- {"provider" : "phosphorr" , "value" : "bridge" },
59- {"value" : "bridge" },
60- {"provider" : "phosphor" },
61- 7 ,
62- None ,
60+ {"icon_provider" : "phosphorr" , "icons" : {"big bridge" : "bridge" }},
61+ {"icons" : {"big bridge" : "bridge" }},
62+ {"icon_provider" : None , "icons" : {"big bridge" : "bridge" }},
6363 ],
64- ids = ["unknown-provider" , "no-provider" , "no-value" , "number" , " null" ],
64+ ids = ["unknown-provider" , "no-provider" , "null-provider " ],
6565)
66- def test_malformed_entry_stops_the_app_from_starting ( entry ):
66+ def test_malformed_config_stops_the_app_from_starting ( styles ):
6767 """Bad marker_styles config is a deploy-time mistake, so it raises rather than
6868 quietly costing a pin its icon - the same stance create_location_model takes on a
6969 category with no allowed values."""
70- with pytest .raises ((KeyError , TypeError , AttributeError )):
71- resolve_marker_styles ({ "icons" : { "big bridge" : entry }} )
70+ with pytest .raises ((KeyError , TypeError )):
71+ resolve_marker_styles (styles )
7272
7373
7474def test_empty_marker_styles_stays_empty ():
7575 assert resolve_marker_styles ({}) == {}
7676
7777
78- def test_missing_icons_key_is_not_invented ():
79- assert resolve_marker_styles ({"icon_field" : "type_of_place" }) == {"icon_field" : "type_of_place" }
78+ @pytest .mark .parametrize ("icons" , [{}, None ], ids = ["empty-table" , "no-icons-key" ])
79+ def test_nothing_to_resolve_needs_no_provider (icons ):
80+ """A deployment that styles pins by color alone never names an icon provider, so an
81+ absent or empty table must not demand one."""
82+ styles = {"icon_field" : "type_of_place" , "colors" : {"10" : "#2e7d32" }}
83+ if icons is not None :
84+ styles ["icons" ] = icons
85+
86+ assert resolve_marker_styles (styles ) == styles
8087
8188
8289def test_every_other_key_is_carried_through_untouched ():
83- """colors maps straight to CSS colors and never had a tagged form , so it - like the
84- two field names - must survive resolution unchanged."""
90+ """colors maps straight to CSS colors and has no provider , so it - like the two field
91+ names - must survive resolution unchanged."""
8592 styles = {
8693 "icon_field" : "type_of_place" ,
8794 "color_field" : "speed_limit" ,
8895 "colors" : {"10" : "#2e7d32" , "50" : "#c62828" },
96+ "icon_provider" : "url" ,
8997 "icons" : {"plain" : "https://e.example/c.svg" },
9098 }
9199
@@ -99,10 +107,7 @@ def test_every_other_key_is_carried_through_untouched():
99107def test_does_not_mutate_the_config_it_was_given ():
100108 """For the json backend this dict is the db's live in-memory config, so resolving in
101109 place would rewrite what the deployment has stored."""
102- styles = {
103- "icon_field" : "type_of_place" ,
104- "icons" : {"big bridge" : {"provider" : "phosphor" , "value" : "bridge" }},
105- }
110+ styles = {"icon_provider" : "phosphor" , "icons" : {"big bridge" : "bridge" }}
106111 before = copy .deepcopy (styles )
107112 icons_before = styles ["icons" ]
108113
0 commit comments