2020def foo_compiler ():
2121 return CategoryCompiler (None , 'foo' )
2222
23+
2324@pytest .fixture
2425def foo_compiler_plugin ():
2526 return CategoryPlugin (Mock (category = 'foo' , __name__ = 'foo' ), ['bar' ])
2627
28+
2729@pytest .fixture
2830def foo_baz_builder_plugin ():
29- builder = InstanceCompilerPlugin (lambda : "FOO" , [], name = 'baz' ,
31+ builder = InstanceCompilerPlugin (lambda : "FOO" , [], name = 'baz' ,
3032 aliases = ['qux' ])
3133 builder .category = 'foo'
3234 return builder
3335
36+
3437### CONSTANTS ##############################################################
3538
3639COMPILER_LOC = "paths_cli.compiling.root_compiler._COMPILERS"
3740BASE = "paths_cli.compiling.root_compiler."
3841
42+
3943### TESTS ##################################################################
4044
4145@pytest .mark .parametrize ('input_string' , ["foo-bar" , "FOO_bar" , "foo bar" ,
4246 "foo_bar" , "foo BAR" ])
4347def test_clean_input_key (input_string ):
4448 assert clean_input_key (input_string ) == "foo_bar"
4549
50+
4651@pytest .mark .parametrize ('input_name' , ['canonical' , 'alias' ])
4752def test_canonical_name (input_name ):
4853 compilers = {'canonical' : "FOO" }
@@ -51,6 +56,7 @@ def test_canonical_name(input_name):
5156 patch .dict (BASE + "_ALIASES" , aliases ) as aliases_ :
5257 assert _canonical_name (input_name ) == "canonical"
5358
59+
5460class TestCategoryCompilerProxy :
5561 def setup (self ):
5662 self .compiler = CategoryCompiler (None , "foo" )
@@ -86,6 +92,7 @@ def _bar_dispatch(dct):
8692 with patch .dict (COMPILER_LOC , {'foo' : foo_compiler }):
8793 assert proxy (user_input ) == "bazbaz"
8894
95+
8996def test_compiler_for_nonexisting ():
9097 # if nothing is ever registered with the compiler, then compiler_for
9198 # should error
@@ -97,20 +104,23 @@ def test_compiler_for_nonexisting():
97104 with pytest .raises (RuntimeError , match = "No CategoryCompiler" ):
98105 proxy ._proxy
99106
107+
100108def test_compiler_for_existing (foo_compiler ):
101109 # if a compiler already exists when compiler_for is called, then
102110 # compiler_for should get that as its proxy
103111 with patch .dict (COMPILER_LOC , {'foo' : foo_compiler }):
104112 proxy = compiler_for ('foo' )
105113 assert proxy ._proxy is foo_compiler
106114
115+
107116def test_compiler_for_unregistered (foo_compiler ):
108117 # if a compiler is registered after compiler_for is called, then
109118 # compiler_for should use that as its proxy
110119 proxy = compiler_for ('foo' )
111120 with patch .dict (COMPILER_LOC , {'foo' : foo_compiler }):
112121 assert proxy ._proxy is foo_compiler
113122
123+
114124def test_compiler_for_registered_alias (foo_compiler ):
115125 # if compiler_for is registered as an alias, compiler_for should still
116126 # get the correct compiler
@@ -121,12 +131,14 @@ def test_compiler_for_registered_alias(foo_compiler):
121131 proxy = compiler_for ('bar' )
122132 assert proxy ._proxy is foo_compiler
123133
134+
124135def test_get_compiler_existing (foo_compiler ):
125136 # if a compiler has been registered, then _get_compiler should return the
126137 # registered compiler
127138 with patch .dict (COMPILER_LOC , {'foo' : foo_compiler }):
128139 assert _get_compiler ('foo' ) is foo_compiler
129140
141+
130142def test_get_compiler_nonexisting (foo_compiler ):
131143 # if a compiler has not been registered, then _get_compiler should create
132144 # the compiler
@@ -136,6 +148,18 @@ def test_get_compiler_nonexisting(foo_compiler):
136148 assert compiler .label == 'foo'
137149 assert 'foo' in _COMPILERS
138150
151+
152+ def test_get_compiler_nonstandard_name_multiple ():
153+ # regression test based on real issue -- there was an error where
154+ # non-canonical names (e.g., names that involved hyphens instead of
155+ # underscores) would overwrite the previously created compiler instead
156+ # of getting the identical object
157+ with patch .dict (COMPILER_LOC , {}):
158+ c1 = _get_compiler ('non-canonical-name' )
159+ c2 = _get_compiler ('non-canonical-name' )
160+ assert c1 is c2
161+
162+
139163@pytest .mark .parametrize ('canonical,aliases,expected' , [
140164 ('foo' , ['bar' , 'baz' ], ['foo' , 'bar' , 'baz' ]),
141165 ('foo' , ['baz' , 'bar' ], ['foo' , 'baz' , 'bar' ]),
@@ -149,6 +173,7 @@ def test_get_registration_names(canonical, aliases, expected):
149173 type(plugin ).name = PropertyMock (return_value = canonical )
150174 assert _get_registration_names (plugin ) == expected
151175
176+
152177def test_register_compiler_plugin (foo_compiler_plugin ):
153178 # _register_compiler_plugin should register compilers that don't exist
154179 compilers = {}
@@ -162,6 +187,7 @@ def test_register_compiler_plugin(foo_compiler_plugin):
162187
163188 assert 'foo' not in _COMPILERS
164189
190+
165191@pytest .mark .parametrize ('duplicate_of' , ['canonical' , 'alias' ])
166192@pytest .mark .parametrize ('duplicate_from' , ['canonical' , 'alias' ])
167193def test_register_compiler_plugin_duplicate (duplicate_of , duplicate_from ):
@@ -184,6 +210,7 @@ def test_register_compiler_plugin_duplicate(duplicate_of, duplicate_from):
184210 with pytest .raises (CategoryCompilerRegistrationError ):
185211 _register_compiler_plugin (plugin )
186212
213+
187214@pytest .mark .parametrize ('compiler_exists' , [True , False ])
188215def test_register_builder_plugin (compiler_exists , foo_baz_builder_plugin ,
189216 foo_compiler ):
@@ -203,6 +230,7 @@ def test_register_builder_plugin(compiler_exists, foo_baz_builder_plugin,
203230 assert type_dispatch ['baz' ] is foo_baz_builder_plugin
204231 assert type_dispatch ['qux' ] is foo_baz_builder_plugin
205232
233+
206234def test_register_plugins_unit (foo_compiler_plugin , foo_baz_builder_plugin ):
207235 # register_plugins should correctly sort builder and compiler plugins,
208236 # and call the correct registration functions
@@ -212,6 +240,7 @@ def test_register_plugins_unit(foo_compiler_plugin, foo_baz_builder_plugin):
212240 assert builder .called_once_with (foo_baz_builder_plugin )
213241 assert compiler .called_once_with (foo_compiler_plugin )
214242
243+
215244def test_register_plugins_integration (foo_compiler_plugin ,
216245 foo_baz_builder_plugin ):
217246 # register_plugins should correctly register plugins
@@ -225,6 +254,7 @@ def test_register_plugins_integration(foo_compiler_plugin,
225254 type_dispatch = _COMPILERS ['foo' ].type_dispatch
226255 assert type_dispatch ['baz' ] is foo_baz_builder_plugin
227256
257+
228258def test_sort_user_categories ():
229259 # sorted user categories should match the expected compile order
230260 aliases = {'quux' : 'qux' }
@@ -245,6 +275,7 @@ def test_sort_user_categories():
245275 # check that we unset properly (test the test)
246276 assert paths_cli .compiling .root_compiler .COMPILE_ORDER [0 ] == 'engine'
247277
278+
248279def test_do_compile ():
249280 # compiler should correctly compile a basic input dict
250281 compilers = {
0 commit comments