1414)
1515
1616
17+ @pytest .fixture
18+ def make_build_config (tmp_path ):
19+ """A fixture for quickly constructing build configs"""
20+
21+ def make (* config_items ):
22+ config = BuildConfig (tmp_path )
23+ if config_items :
24+ with config .transaction ():
25+ config .update_config_items (config_items )
26+ return config
27+
28+ return make
29+
30+
1731@pytest .mark .parametrize (
1832 "value, expectation" ,
1933 [
@@ -134,43 +148,57 @@ def test_find_build_config_item_in_python_file(tmp_path):
134148 }
135149
136150
137- def test_build_config_file_load_absent_config (tmp_path ):
138- assert BuildConfig ( tmp_path ).config == {
151+ def test_build_config_file_load_absent_config (make_build_config ):
152+ assert make_build_config ( ).config == {
139153 "version" : idom .__version__ ,
140154 "by_source" : {},
141155 }
142156
143157
144- def test_build_config_file_repr (tmp_path ):
145- with BuildConfig ( tmp_path ).transaction () as config_file :
158+ def test_build_config_file_repr (make_build_config ):
159+ with make_build_config ( ).transaction () as config_file :
146160 config_file .update_config_items (
147161 [{"source_name" : "a_test" , "js_dependencies" : ["a-different-package" ]}]
148162 )
149163
150164 assert str (config_file ) == f"BuildConfig({ config_file .config } )"
151165
152166
153- def test_build_config_file_add_config_item (tmp_path ):
154- with BuildConfig ( tmp_path ).transaction () as config_file :
167+ def test_build_config_file_add_config_item (make_build_config ):
168+ with make_build_config ( ).transaction () as config_file :
155169 config_file .update_config_items (
156170 [{"source_name" : "a_test" , "js_dependencies" : ["some-js-package" ]}]
157171 )
158172
159- assert BuildConfig ( tmp_path ).config ["by_source" ] == {
173+ assert make_build_config ( ).config ["by_source" ] == {
160174 "a_test" : {"source_name" : "a_test" , "js_dependencies" : ["some-js-package" ]}
161175 }
162176
163177
164178@pytest .mark .parametrize ("method" , ["update_config_items" ])
165- def test_some_build_config_file_methods_require_transaction (tmp_path , method ):
166- config_file = BuildConfig (tmp_path )
167- with pytest .raises (
168- RuntimeError ,
169- match = "Cannot modify BuildConfig without transaction" ,
170- ):
179+ def test_some_build_config_file_methods_require_transaction (make_build_config , method ):
180+ config_file = make_build_config ()
181+ with pytest .raises (RuntimeError , match = "must be used in a transaction" ):
171182 getattr (config_file , method )()
172183
173184
185+ @pytest .mark .parametrize (
186+ "method" ,
187+ [
188+ "get_js_dependency_alias" ,
189+ "all_aliased_js_dependencies" ,
190+ "all_js_dependency_aliases" ,
191+ ],
192+ )
193+ def test_some_build_config_file_methods_blocked_in_transaction (
194+ make_build_config , method
195+ ):
196+ config_file = make_build_config ()
197+ with pytest .raises (RuntimeError , match = "cannot be used in a transaction" ):
198+ with config_file .transaction ():
199+ getattr (config_file , method )()
200+
201+
174202def test_find_python_packages_build_config_items ():
175203 mock_site_pkgs_path = str ((Path (__file__ ).parent / "mock_site_packages" ).absolute ())
176204 configs , errors = find_python_packages_build_config_items ([mock_site_pkgs_path ])
@@ -193,9 +221,9 @@ def test_find_python_packages_build_config_items():
193221 raise errors [0 ].__cause__
194222
195223
196- def test_build_config_file_transaction_rollback (tmp_path ):
224+ def test_build_config_file_transaction_rollback (make_build_config ):
197225 with pytest .raises (Exception ):
198- with BuildConfig ( tmp_path ).transaction () as config_file :
226+ with make_build_config ( ).transaction () as config_file :
199227 config_file .update_config_items (
200228 [
201229 {
@@ -206,7 +234,7 @@ def test_build_config_file_transaction_rollback(tmp_path):
206234 )
207235 raise Exception ()
208236
209- assert BuildConfig ( tmp_path ).config == {
237+ assert make_build_config ( ).config == {
210238 "version" : idom .__version__ ,
211239 "by_source" : {},
212240 }
@@ -229,3 +257,40 @@ def test_split_package_name_and_version(package_specifier, expected_name_and_ver
229257 assert (
230258 split_package_name_and_version (package_specifier ) == expected_name_and_version
231259 )
260+
261+
262+ def test_build_config_get_js_dependency_alias (make_build_config ):
263+ config = make_build_config (
264+ {"source_name" : "module_1" , "js_dependencies" : ["dep1" , "dep2" ]},
265+ {"source_name" : "module_2" , "js_dependencies" : ["dep2" , "dep3" ]},
266+ )
267+ assert config .get_js_dependency_alias ("module_1" , "dep1" ) == "dep1-module_1-5001a4b"
268+ assert config .get_js_dependency_alias ("module_1" , "dep2" ) == "dep2-module_1-5001a4b"
269+ assert config .get_js_dependency_alias ("module_2" , "dep2" ) == "dep2-module_2-46d6db8"
270+ assert config .get_js_dependency_alias ("module_2" , "dep3" ) == "dep3-module_2-46d6db8"
271+
272+
273+ def test_build_config_all_aliased_js_dependencies (make_build_config ):
274+ config = make_build_config (
275+ {"source_name" : "module_1" , "js_dependencies" : ["dep1" , "dep2" ]},
276+ {"source_name" : "module_2" , "js_dependencies" : ["dep2" , "dep3" ]},
277+ )
278+ assert config .all_aliased_js_dependencies () == [
279+ "dep1-module_1-5001a4b@npm:dep1" ,
280+ "dep2-module_1-5001a4b@npm:dep2" ,
281+ "dep2-module_2-46d6db8@npm:dep2" ,
282+ "dep3-module_2-46d6db8@npm:dep3" ,
283+ ]
284+
285+
286+ def test_build_config_all_js_dependency_aliases (make_build_config ):
287+ config = make_build_config (
288+ {"source_name" : "module_1" , "js_dependencies" : ["dep1" , "dep2" ]},
289+ {"source_name" : "module_2" , "js_dependencies" : ["dep2" , "dep3" ]},
290+ )
291+ assert config .all_js_dependency_aliases () == [
292+ "dep1-module_1-5001a4b" ,
293+ "dep2-module_1-5001a4b" ,
294+ "dep2-module_2-46d6db8" ,
295+ "dep3-module_2-46d6db8" ,
296+ ]
0 commit comments