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 38 commits into
base: main
Choose a base branch
from
Draft

Null tests.142 #290

wants to merge 38 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?

test_yaml = Path(f"null_example/null_model.yaml")

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

Choose a reason for hiding this comment

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

this is probably why we keep seeing some failures

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a difference between this file and fre/make/tests/null_example/test_basic_null_yaml.py? I think we can get rid of the one in null_example/

Copy link
Collaborator

Choose a reason for hiding this comment

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

2 things:

  1. Can we put this with the other tests too? (Just in fre/make/tests - back one directory)
  2. Can we rename this test_create_checkout.py? I think the trend is to name the test file after the tool it's testing.

Copy link
Member

Choose a reason for hiding this comment

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

+1

@ilaflott
Copy link
Member

for the rm -rf, instead of subprocess, consider shutil.rmtree

"""
Make sure checkout file exists
"""
subprocess.run(["rm","-rf",f"{OUT}/fremake_canopy/test/null_model_full/src/checkout.sh"])
Copy link
Member

Choose a reason for hiding this comment

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

the fremake_canopy/ part seems old/out-of-date. double check the directory structure being created locally and adjust what path you're attempting to remove and then check for in the assert below

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, yeah the fremake_canopy bit is actually a part of a path set in the platforms.yaml. Good point, it should be updated, but I don't thiiiiink that specific part is the problem. I still agree, always double check the path/directory structure for sure though!

"""
check if --verbose option works
"""
create_checkout_script.checkout_create(YAMLFILE,PLATFORM,TARGET,False,False, False,True)
Copy link
Member

Choose a reason for hiding this comment

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

@singhd789 @thomas-robinson perhaps create_checkout_script should return the full path to checkout.sh? instead of just printing it to screen?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, the whole path to the checkout script is printed (and it's made executable) - that way the user knows where it is and could also run it themselves if they want. What would be another benefit of returning it as well? Just curious

Copy link
Member

Choose a reason for hiding this comment

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

this test + the otheres could become a simple:

compile_sh_path =  create_checkout_script (<BLAH ARGS>)
assert Path(compile_sh_path).exists()

similarly, elsewhere in the code base, if create_checkout_script is being used, that returned string object could be actually leveraged by other functions. If it's just print, then there is no option to do so



if jobs == 'False' and execute == True:
sys.exit('jobs must be defined as number if --execute flag is True')
Copy link
Member

Choose a reason for hiding this comment

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

don't use sys.exit, raise ValueError('text-here') or smth.

@@ -18,7 +18,9 @@ def checkout_create(yamlfile, platform, target, no_parallel_checkout, jobs, exec
run = execute
jobs = str(jobs)
pcheck = no_parallel_checkout


if jobs == 'False' and execute == True:
Copy link
Member

Choose a reason for hiding this comment

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

why is jobs a string of a bool? Why are we checking if execute is True using an equality operator? Why can't this be- if not jobs and execute: ?

check if --execute option works
"""
subprocess.run(["rm","-rf",f"{OUT}/fremake_canopy/test"])
create_checkout_script.checkout_create(YAMLFILE,PLATFORM,TARGET,False,2, True,False)
Copy link
Member

Choose a reason for hiding this comment

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

OK so i saw that what brought this PR's checks from red-x to green-check is the change of this functions argument from a boolean value to an integer 2. This suggests to me that it's hard to track what these arguments are supposed to be when developing the code, so checkout_create needs explicit keyword arguments, not positional.

this line should read like:

create_checkout_script.checkout_create(
    yamlfile = YAMLFILE, 
    platform = PLATFORM, 
    target = TARGET, 
    no_parallel_checkout = False, 
    jobs = 2, 
    execute = True, 
    verbose = False )

test_yaml = Path(f"null_example/null_model.yaml")

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

Choose a reason for hiding this comment

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

str(Path(f"STUFF")) here could just be f"STUFF"

Copy link
Member

Choose a reason for hiding this comment

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

also os.environ["HOME"] needs to be set back to it's original value, or it will be set to f"{CWD}/{test_dir}/configure_yaml_out" for ALL other testing routine calls

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.

3 participants