Multiple dependencies#
Tests can depend on more than one dependency, for example, the test blt depends on the bacon, lettuce, and tomato instance of ingredients:
# Copyright NTESS. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT
import canary
canary.directives.parameterize("type", ("eggs", "ham", "lettuce", "bacon", "tomato"))
def test():
instance = canary.get_instance()
assert instance is not None
if __name__ == "__main__":
test()
# Copyright NTESS. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT
import sys
import canary
canary.directives.depends_on("ingredients.type=bacon")
canary.directives.depends_on("ingredients.type=lettuce")
canary.directives.depends_on("ingredients.type=tomato")
def blt() -> int:
instance = canary.get_instance()
for dep in instance.dependencies:
assert dep.family == "ingredients"
assert dep.parameters.type in ("bacon", "lettuce", "tomato")
if __name__ == "__main__":
sys.exit(blt())
A graph of the dependency tree can be generated by canary find -g:
$ canary find -k 'not kitchen_sink' -g -r ./depends_on/multi
INFO: Collecting generator files from depends_on/multi
INFO: Instantiating generators from collected files
INFO: Generating test specs from generators
INFO: Searching for duplicated tests
INFO: Resolving test spec dependencies
INFO: Generated 8 test specs from 4 generators
INFO: Selecting specs based on 1 rules
INFO: Selected 7 test specs
INFO: Excluded 1 test spec during selection
Reason Count
─────────────────────────────────────────────────────────────
keyword expression 'not kitchen_sink' did not match 1
├── blt
│ ├── ingredients.type=bacon
│ ├── ingredients.type=lettuce
│ └── ingredients.type=tomato
└── green_eggs_and_ham
│ ├── ingredients.type=eggs
│ └── ingredients.type=ham
Pattern matches#
Glob patterns can be used to match multiple dependencies, as demonstrated in the kitchen_sink test case:
# Copyright NTESS. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT
import sys
import canary
canary.directives.depends_on("ingredients.type=*")
def blt() -> int:
instance = canary.get_instance()
for dep in instance.dependencies:
assert dep.family == "ingredients"
if __name__ == "__main__":
sys.exit(blt())
A graph of the dependency tree can be generated by canary find -g:
$ canary find -k 'not green_eggs_and_ham and not blt' -g -r ./depends_on/multi
INFO: Collecting generator files from depends_on/multi
INFO: Instantiating generators from collected files
INFO: Generating test specs from generators
INFO: Searching for duplicated tests
INFO: Resolving test spec dependencies
INFO: Generated 8 test specs from 4 generators
INFO: Selecting specs based on 1 rules
INFO: Selected 6 test specs
INFO: Excluded 2 test specs during selection
Reason Count
───────────────────────────────────────────────────────────────────────────────
keyword expression 'not green_eggs_and_ham and not blt' did not match 2
└── kitchen_sink
│ ├── ingredients.type=eggs
│ ├── ingredients.type=ham
│ ├── ingredients.type=lettuce
│ ├── ingredients.type=bacon
│ └── ingredients.type=tomato