Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore alternative solutions to dynamically determining paths to data needed for automated testing #570

Open
robertbartel opened this issue Apr 4, 2024 · 1 comment
Labels
enhancement New feature or request maas MaaS Workstream

Comments

@robertbartel
Copy link
Contributor

As discussed in some comment threads in #566 (like this one), attempting to run some of DMOD tests will fail the code was not obtained by cloning the repo via Git. This is because Git-based functionality is utilized as a step to determining the correct path for testing files.

This approach was adopted because it satisfied two requirements:

  1. avoiding use of absolute paths
  2. tests could be executed from any working directory within the repo directory structure

The reason the first item is required is fairly clear, but I don't remember exactly why the second is. I believe it has to do with the way certain test tools (perhaps our tests scripts also) run tests, and also the way certain IDEs execute tests when run through their interface.

In the interests of compatibility, we should explore whether there is an alternative, more general method that still satisfies our current needs with respect to automated testing.

@robertbartel robertbartel added enhancement New feature or request maas MaaS Workstream labels Apr 4, 2024
@christophertubbs
Copy link
Contributor

An approach I've used before here was acknowledging a known pattern for the root directory and climbing up the directory chain from the CWD to the root to find a directory that fits the profile. In bash, I did:

        path=$(realpath .);

        while [ "$path" != "/" ]; do
            # Get the base name of the directory in lower case - for something like 'Path/To/DiReCtOrY', this will yield
            # 'directory'
            lowercase_base=$(basename "$path" | tr "[:upper:]" "[:lower:]")

            # Check if the directory name is some form of 'dmod' and that it contains a 'scripts' and 'python' directory
            if [ "$lowercase_base" = "dmod" ] && [ -d "${path}/scripts" ] && [ -d "${path}/python" ]; then
                # If it exists, echo the path so it may be caught by the caller and exit the function
                echo "$path"
                return 0;
            fi

            # Reassign path investigate the parent
            path=$(dirname "$path");
        done

It's ugly as hell, but it got the job done in the one case I tried it. Maybe that'll help as a jumping off point.

Austin has also stated in the past that moving 100% over to pytest over unittest will provide utilities for making sure all the tests can find the resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maas MaaS Workstream
Projects
None yet
Development

No branches or pull requests

2 participants