@@ -351,7 +351,9 @@ def declare_component(
351
351
self .raw_component_decls [name ] = required_qualifier_configuration
352
352
353
353
def __force_default_values (
354
- self , qualifier_dict : dict [str , str ]
354
+ self ,
355
+ qualifier_dict : dict [str , str ],
356
+ ignore_test_only : bool = False ,
355
357
) -> dict [str , str | bool ]:
356
358
"""Force the default value of the qualifiers.
357
359
@@ -366,6 +368,8 @@ def __force_default_values(
366
368
367
369
:param qualifier_dict: The dictionary of qualifiers for which the default
368
370
values are required.
371
+ :param ignore_test_only: If set to True, the qualifier marked as test_only are
372
+ completely ignored
369
373
"""
370
374
if not self .is_declaration_phase_finished :
371
375
raise AnodError (
@@ -379,6 +383,10 @@ def __force_default_values(
379
383
380
384
# Add the required default values
381
385
for qualifier_name , qualifier in self .qualifier_decls .items ():
386
+ # Ignore test_only qualifier if needed
387
+ if qualifier ["test_only" ] and ignore_test_only :
388
+ continue
389
+
382
390
if qualifier ["type" ] == self .__KEY_VALUE_QUALIFIER :
383
391
if qualifier_name not in qualifier_dict :
384
392
# The qualifier must have a default. This is checked by
@@ -398,7 +406,9 @@ def __force_default_values(
398
406
return qualifier_dict_with_default
399
407
400
408
def __check_qualifier_consistency (
401
- self , qualifier_configuration : dict [str , str ]
409
+ self ,
410
+ qualifier_configuration : dict [str , str ],
411
+ ignore_test_only : bool = False ,
402
412
) -> None :
403
413
"""Check that the qualifiers are compliant with their declarations.
404
414
@@ -409,6 +419,8 @@ def __check_qualifier_consistency(
409
419
410
420
:param qualifier_configuration: A dictionary of qualifiers to be checked.
411
421
The key are the qualifiers names and the values the qualifier values.
422
+ :param ignore_test_only: If set to True, the qualifier marked as test_only are
423
+ completely ignored
412
424
"""
413
425
# The declaration phase must be finished to ensure the consistency of the result
414
426
if not self .is_declaration_phase_finished :
@@ -427,6 +439,10 @@ def __check_qualifier_consistency(
427
439
428
440
qualifier = self .qualifier_decls [qualifier_name ]
429
441
442
+ # Ignore the test_only qualifier if needed
443
+ if ignore_test_only and qualifier ["test_only" ]:
444
+ continue
445
+
430
446
# If the qualifier is test_only and the current anod kind is not test,
431
447
# raise an error.
432
448
if qualifier ["test_only" ] and self .anod_instance .kind != "test" :
@@ -465,6 +481,12 @@ def __check_qualifier_consistency(
465
481
466
482
# Make sure all the declared qualifiers are stated
467
483
for qualifier_name , qualifier in self .qualifier_decls .items ():
484
+ # Ignore test_only qualifier if needed
485
+ if qualifier ["test_only" ] and (
486
+ ignore_test_only or self .anod_instance .kind != "test"
487
+ ):
488
+ continue
489
+
468
490
if qualifier ["type" ] == self .__KEY_VALUE_QUALIFIER :
469
491
if qualifier_name not in qualifier_configuration :
470
492
# The qualifier must have a default otherwise it would not have
@@ -530,12 +552,24 @@ def __end_declaration_phase(self) -> None:
530
552
# Add some context informations to the errors raised by
531
553
# __check_qualifier_consistency to ease the debugging process.
532
554
try :
533
- self .__check_qualifier_consistency (qualifier_dict )
555
+ self .__check_qualifier_consistency (
556
+ qualifier_dict ,
557
+ ignore_test_only = True ,
558
+ )
534
559
except AnodError as e :
535
560
raise AnodError (f'In component "{ component } ": { str (e )} ' ) from e
536
561
562
+ # Make sure no test_only qualifier is used in a component definition
563
+ for q in qualifier_dict :
564
+ if self .qualifier_decls [q ]["test_only" ]:
565
+ raise AnodError (
566
+ f'In component "{ component } ": The qualifier "{ q } " is'
567
+ " test_only and cannot be used to define a component"
568
+ )
569
+
537
570
qualifier_dict_with_default_values = self .__force_default_values (
538
- qualifier_dict
571
+ qualifier_dict ,
572
+ ignore_test_only = True ,
539
573
)
540
574
541
575
qualifier_configuration = self .__qualifier_config_repr (
@@ -577,7 +611,9 @@ def parse(self, user_qualifiers: dict[str, str]) -> None:
577
611
self .__check_qualifier_consistency (user_qualifiers )
578
612
579
613
# Add the default values
580
- self .qualifier_values = self .__force_default_values (user_qualifiers )
614
+ self .qualifier_values = self .__force_default_values (
615
+ user_qualifiers , ignore_test_only = self .anod_instance .kind != "test"
616
+ )
581
617
582
618
def __get_parsed_qualifiers (self ) -> dict [str , str | bool ]:
583
619
"""Return the parsed qualifier dictionary.
@@ -619,6 +655,12 @@ def __generate_qualifier_part(
619
655
# Assuming that the qualifier has been declared.
620
656
# In practice, this is checked by build_space_name before it call this function.
621
657
qualifier = self .qualifier_decls [qualifier_name ]
658
+
659
+ # If the qualifier is test_only and the anod kind is not test then the
660
+ # qualifier is ignored.
661
+ if qualifier ["test_only" ] and self .anod_instance .kind != "test" :
662
+ return ""
663
+
622
664
qualifier_value = parsed_qualifiers [qualifier_name ]
623
665
624
666
# Hold the part of the suffix induced by the qualifier.
@@ -675,10 +717,17 @@ def component(self) -> str | None:
675
717
"declaration phase"
676
718
)
677
719
720
+ # Remove the test_only qualifier as they are not used for the component
721
+ qualifier_configuration = {
722
+ q : v
723
+ for q , v in self .__get_parsed_qualifiers ().items ()
724
+ if not self .qualifier_decls [q ]["test_only" ]
725
+ }
726
+
678
727
# This ensured by __end_declaration_phase
679
728
assert self .component_names is not None
680
729
return self .component_names .get (
681
- self .__qualifier_config_repr (self . __get_parsed_qualifiers () )
730
+ self .__qualifier_config_repr (qualifier_configuration )
682
731
)
683
732
684
733
@property
0 commit comments