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

Null tests.142 #290

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft

Null tests.142 #290

wants to merge 24 commits into from

Conversation

kiihne-noaa
Copy link
Contributor

Describe your changes

Added tests in fre/make/null_example for checkout

Issue ticket number and link (if applicable)

creating this so Dana can help with debugging of issues with paths

Checklist before requesting a review

@singhd789

@singhd789 singhd789 self-requested a review December 11, 2024 16:41
@@ -0,0 +1,45 @@
#tests for the create-checkout step of fre-make, for null_model.yaml
import os
from fre import fre
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this, not needed

Comment on lines 5 to 6
from fre.pp import configure_script_yaml as csy
from click.testing import CliRunner
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove these too, not needed. We won't be using runner.invoke for these tool tests here

from fre.pp import configure_script_yaml as csy
from click.testing import CliRunner
import subprocess
from fre.make import createCheckout
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated: createCheckout --> create_checkout_script

Comment on lines 11 to 16
test_dir = Path("fre/make/tests/null_example")
yamlfile = Path(f"{test_dir}/null_model.yaml")

#set platform and target
platform = "ncrc5.intel"
target = "debug"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep consistency with other tests, make these variable names capitalized.

Comment on lines 11 to 12
test_dir = Path("fre/make/tests/null_example")
yamlfile = Path(f"{test_dir}/null_model.yaml")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend keeping all the tests together in fre/make/tests for now. We can move it there and make this

TEST_DIR = Path("fre/make/tests")
YAMLFILE = Path(f"{TEST_DIR}/null_example/null_model.yaml")


# Set home for ~/cylc-src location in script
#os.environ["HOME"]=str(Path(f"{out_dir}"))
HOME_DIR = os.environ["HOME"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So through doing this, we've found it definitely effects other tests that use HOME.

  1. Let's move re-setting HOME to inside each test that needs it AND make sure to save the default HOME location first. We can look at how Ryan maneuvered it:
    define home:
    def_home = str(os.environ["HOME"])

    set home:
    os.environ["HOME"]=OUT#str(Path(OUT))

    reset home:
    os.environ["HOME"] = def_home

Comment on lines +18 to +17
#set output directory
#out_dir = Path(f"fre/make/tests/null_example/fre_make_out")
#Path(out_dir).mkdir(parents=True,exist_ok=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, I feel like it would be nice it each test had output that was easy to find. Here, for the checkout, maybe we can set OUT to be:

OUT = f"{TEST_DIR}/checkout_out"

Where test_dir would be what I commented above. Also add in the out location to the .gitignore file

#os.environ["HOME"]=str(Path(f"{out_dir}"))
HOME_DIR = os.environ["HOME"]
#run checkout command
runner = CliRunner()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

"""
Make sure checkout file exists
"""
result = runner.invoke(fre.fre, args=["make","create-checkout","-y",yamlfile,"-p",platform,"-t",target])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using runner.invoke is good for testing the cli for fre. For actually script functionality testing here, we're going to call the actual functions in the script.

Using from fre.make import create_checkout_script from the top:

  1. we'll set/reset home as I mentioned above
  2. we'll set what would be click options passed by the user for the fre make create-checkout command
  3. we'll invoke the main checkout function
  4. check for the existence of the checkout script as a good starting test

You have line 33 that just needs to be edited a little. Try this:
create_checkout_script.checkout_create(variables set right before)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different than the test_basic_null_yaml.py file in fre/make/tests/null_example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants