Fix comparisons for abstract specs (#20341)
bug only relevant for python3
This commit is contained in:
		 Greg Becker
					Greg Becker
				
			
				
					committed by
					
						 Tamara Dahlgren
						Tamara Dahlgren
					
				
			
			
				
	
			
			
			 Tamara Dahlgren
						Tamara Dahlgren
					
				
			
						parent
						
							12d035b225
						
					
				
				
					commit
					378af922a2
				
			| @@ -3517,8 +3517,11 @@ def ne_dag(self, other, deptypes=True): | |||||||
| 
 | 
 | ||||||
|     def _cmp_node(self): |     def _cmp_node(self): | ||||||
|         """Comparison key for just *this node* and not its deps.""" |         """Comparison key for just *this node* and not its deps.""" | ||||||
|         return (self.name, |         # Name or namespace None will lead to invalid comparisons for abstract | ||||||
|                 self.namespace, |         # specs. Replace them with the empty string, which is not a valid spec | ||||||
|  |         # name nor namespace so it will not create spurious equalities. | ||||||
|  |         return (self.name or '', | ||||||
|  |                 self.namespace or '', | ||||||
|                 tuple(self.versions), |                 tuple(self.versions), | ||||||
|                 self.variants, |                 self.variants, | ||||||
|                 self.architecture, |                 self.architecture, | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| # Spack Project Developers. See the top-level COPYRIGHT file for details. | # Spack Project Developers. See the top-level COPYRIGHT file for details. | ||||||
| # | # | ||||||
| # SPDX-License-Identifier: (Apache-2.0 OR MIT) | # SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||||||
| 
 | import itertools | ||||||
| import os | import os | ||||||
| import pytest | import pytest | ||||||
| import shlex | import shlex | ||||||
| @@ -806,3 +806,26 @@ def test_kv_with_spaces(self): | |||||||
|     ]) |     ]) | ||||||
|     def test_target_tokenization(self, expected_tokens, spec_string): |     def test_target_tokenization(self, expected_tokens, spec_string): | ||||||
|         self.check_lex(expected_tokens, spec_string) |         self.check_lex(expected_tokens, spec_string) | ||||||
|  | 
 | ||||||
|  |     @pytest.mark.regression('20310') | ||||||
|  |     def test_compare_abstract_specs(self): | ||||||
|  |         """Spec comparisons must be valid for abstract specs. | ||||||
|  | 
 | ||||||
|  |         Check that the spec cmp_key appropriately handles comparing specs for | ||||||
|  |         which some attributes are None in exactly one of two specs""" | ||||||
|  |         # Add fields in order they appear in `Spec._cmp_node` | ||||||
|  |         constraints = [ | ||||||
|  |             None, | ||||||
|  |             'foo', | ||||||
|  |             'foo.foo', | ||||||
|  |             'foo.foo@foo', | ||||||
|  |             'foo.foo@foo+foo', | ||||||
|  |             'foo.foo@foo+foo arch=foo-foo-foo', | ||||||
|  |             'foo.foo@foo+foo arch=foo-foo-foo %foo', | ||||||
|  |             'foo.foo@foo+foo arch=foo-foo-foo %foo cflags=foo', | ||||||
|  |         ] | ||||||
|  |         specs = [Spec(s) for s in constraints] | ||||||
|  | 
 | ||||||
|  |         for a, b in itertools.product(specs, repeat=2): | ||||||
|  |             # Check that we can compare without raising an error | ||||||
|  |             assert a <= b or b < a | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user