Copying and linking resource files into the test execution directory#
Resources needed by tests can be copied and linked from their source locations to the execution directory with the canary.directives.copy() and canary.directives.link() directives, respectively, as shown in the following example:
# Copyright NTESS. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: MIT
import os
import canary
canary.directives.copy("copy.txt")
canary.directives.link("link.txt")
canary.directives.copy("${NAME}.*.txt")
def test():
assert os.path.exists("copy.txt") and not os.path.islink("copy.txt")
assert os.path.exists("link.txt") and os.path.islink("link.txt")
assert os.path.exists("copy_and_link.1.txt") and not os.path.islink("copy_and_link.1.txt")
assert os.path.exists("copy_and_link.2.txt") and not os.path.islink("copy_and_link.2.txt")
if __name__ == "__main__":
test()
$ canary run ./copy_and_link
...
$ cd $(canary location copy_and_link); ls -l *.txt
-rw-r--r-- 1 docs docs 2184 Jun 4 20:43 canary-out.txt
-rw-r--r-- 1 docs docs 0 Jun 4 20:43 copy.txt
-rw-r--r-- 1 docs docs 0 Jun 4 20:43 copy_and_link.1.txt
-rw-r--r-- 1 docs docs 0 Jun 4 20:43 copy_and_link.2.txt
lrwxrwxrwx 1 docs docs 118 Jun 4 20:43 link.txt -> /home/docs/checkouts/readthedocs.org/user_builds/canary-wm/checkouts/latest/src/canary/examples/copy_and_link/link.txt