Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pgierz committed Sep 2, 2024
1 parent 6863c1e commit 6c05de0
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
40 changes: 40 additions & 0 deletions .github/workflows/vcs-test.yml
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
2 changes: 2 additions & 0 deletions configs/components/dummy_model/dummy_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ available_versions:
choose_version:
'1.0':
branch: main
comp_command: ${defaults.comp_command}
clean_command: ${defaults.clean_command}
git-repository: "https://github.com/esm-tools/dummy-model.git"
contact: "paul.gierz(at)awi.de"
install_bins: bin/helloWorld
Expand Down
2 changes: 1 addition & 1 deletion configs/machines/generic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pool_dir: "/path/not/set/for/generic/yaml/"

# standard environment setup
module_actions:
- "load something"
- "load null" # NOTE(PG): The `null` module is provided as an example by modern modulefiles distributions

# some yamls use computer.fc, etc to identify the compiler, so we need to add them
fc: "unset"
Expand Down
26 changes: 26 additions & 0 deletions docs/local-testing.rst
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
56 changes: 56 additions & 0 deletions tests/test_esm_runscripts/test_vcs_helpers.py
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"}

0 comments on commit 6c05de0

Please sign in to comment.