-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: CI for VCS | ||
on: | ||
push: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
- name: Update apt-get | ||
run: sudo apt-get update -y && sudo apt-get upgrade -y | ||
- name: Install Dependencies | ||
run: | | ||
sudo apt-get install -y \ | ||
build-essential \ | ||
gfortran \ | ||
libnetcdf-dev \ | ||
libnetcdff-dev \ | ||
libhdf5-dev | ||
- name: Install up Cmake | ||
run: sudo apt-get install -y cmake | ||
- name: Install modulefiles | ||
run: | | ||
sudo apt-get install -y environment-modules | ||
source /etc/profile.d/modules.sh | ||
- name: Set up work folders | ||
run: | | ||
sudo mkdir -p /work/esm-bot/my-project/model-codes | ||
sudo mkdir -p /work/esm-bot/my-project/experiments | ||
sudo mkdir -p /work/esm-bot/my-project/run-configs | ||
- name: Install esm-tools | ||
run: "export LC_ALL=\"en_US.UTF-8\"\nexport LANG=\"en_US.UTF-8\" \nPATH=${HOME}/.local/bin:${PATH}\n./install.sh\n" | ||
- name: Set up the dummy model | ||
run: | | ||
cd /work/esm-bot/my-project/model-codes | ||
PATH=${HOME}/.local/bin:${PATH} | ||
esm_master install-dummy_model-1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
============= | ||
Local Testing | ||
============= | ||
|
||
There are a few ways to test locally. One way is to leverage ``docker``. The | ||
github CI workflow ``dummy-model.yml`` can be used as reference. You can use it | ||
together with the ``act`` (https://github.com/nektos/act) tool to set up the ``esm-tools``, | ||
and install the ``dummy-model``. That is a good starting point for futher tests:: | ||
|
||
act -w "./.github/workflows/dummy-model.yml" -r | ||
|
||
The ``-r`` flag keeps the container afterwards. You can then use ``docker exec`` to enter | ||
the container and do further experimentation:: | ||
|
||
docker container ls | ||
docker exec -it <container_id> /bin/bash | ||
|
||
By default, you have the following structure: | ||
* ``/work/esm-bot/my-project/model-codes`` | ||
* ``/work/esm-bot/my-project/run-configs`` | ||
* ``/work/esm-bot/my-project/experiments`` | ||
|
||
Note that you need to switch to this user first when you start the | ||
interactive docker session!:: | ||
|
||
su - esm-bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import time | ||
import pytest | ||
from esm_runscripts.helpers import CachedFile | ||
|
||
|
||
class TestCachedFile: | ||
@pytest.fixture(autouse=True) | ||
def setup_and_teardown(self): | ||
self.test_file_1 = "test1.txt" | ||
self.test_file_2 = "test2.txt" | ||
self.test_file_3 = "test.txt" | ||
self.test_file_4 = "test.yaml" | ||
yield | ||
os.remove(self.test_file_1) | ||
os.remove(self.test_file_2) | ||
os.remove(self.test_file_3) | ||
os.remove(self.test_file_4) | ||
|
||
def test_init(self): | ||
cf = CachedFile(self.test_file_3) | ||
assert cf.path == self.test_file_3 | ||
|
||
def test_is_younger_than(self): | ||
with open(self.test_file_1, "w") as f: | ||
f.write("test") | ||
time.sleep(1) # delay for 1 second | ||
with open(self.test_file_2, "w") as f: | ||
f.write("test") | ||
cf1 = CachedFile(self.test_file_1) | ||
cf2 = CachedFile(self.test_file_2) | ||
assert not cf1.is_younger_than(cf2.path) | ||
|
||
def test_is_older_than(self): | ||
with open(self.test_file_1, "w") as f: | ||
f.write("test") | ||
time.sleep(1) # delay for 1 second | ||
with open(self.test_file_2, "w") as f: | ||
f.write("test") | ||
cf1 = CachedFile(self.test_file_1) | ||
cf2 = CachedFile(self.test_file_2) | ||
assert cf1.is_older_than(cf2.path) | ||
|
||
def test_read(self): | ||
with open(self.test_file_3, "w") as f: | ||
f.write("test") | ||
time.sleep(1) # delay for 1 second | ||
cf = CachedFile(self.test_file_3) | ||
assert cf.read() == "test" | ||
|
||
def test_load_cache(self): | ||
with open(self.test_file_4, "w") as f: | ||
f.write("test: test") | ||
time.sleep(1) # delay for 1 second | ||
cf = CachedFile(self.test_file_4) | ||
assert cf.load_cache() == {"test": "test"} |