Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/esm_tools_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:

- name: Run Pytest
run: |
pip install pytest
# Install test requirements
pip install .[test]
pytest -v .
# For now, only test actual source code. Stuff like coupling scripts is ignored
pytest -v --doctest-modules src --ignore src/esm_runscripts/coupling --ignore-glob "*backup*"
Expand Down
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

"""The setup script."""

from setuptools import setup, find_packages
from os import getenv

from setuptools import find_packages, setup

with open("README.rst") as readme_file:
readme = readme_file.read()

Expand Down Expand Up @@ -38,7 +39,11 @@

setup_requirements = []

test_requirements = ["pyfakefs"]
test_requirements = ["pytest", "pyfakefs"]

extras = {
"test": test_requirements,
}

setup(
author="Dirk Barbi",
Expand Down Expand Up @@ -90,6 +95,7 @@
setup_requires=setup_requirements,
test_suite="tests",
tests_require=test_requirements,
extras_require=extras,
url="https://github.com/esm-tools/esm_tools",
version="6.13.4",
zip_safe=False,
Expand Down
10 changes: 10 additions & 0 deletions src/esm_runscripts/filedicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
The file-dictionary implementation
"""


def copy_files(config):
"""Copies files"""
# PG: No. We do not want this kind of general function. This is just to
# demonstrate how the test would work
return config
41 changes: 41 additions & 0 deletions tests/test_esm_runscripts/test_filedicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Unit tests for the new file-dict feature

Some considerations
~~~~~~~~~~~~~~~~~~~
* It might be clever to put the "fake config" somewhere in the top level, but
then again, it would be nice to have a unique config for each test. This is
undeniably more verbose, but we then have very clear examples to follow when
we want to translate later on.
* You _could_ use the config in each function to generate the fake files, to
avoid repeating yourself; however, that adds real programming logic into the
unit test, which you don't really want.
"""
import os

import yaml

import esm_runscripts.filedicts


def test_example(fs):
# Make a fake config:
config = """
general:
base_dir: /some/dummy/location/
echam:
simulation_files:
jan_surf:
name: ECHAM Jan Surf File
path_in_pool: /work/ollie/pool/ECHAM/T63CORE2_jan_surf.nc
name_in_work: unit.24
"""
config = yaml.safe_load(config)
# Create some fake files and directories you might want in your test
fs.create_file("/work/ollie/pool/ECHAM/T63CORE2_jan_surf.nc")
fs.create_dir("/some/dummy/location/expid/run_18500101-18501231/work")
# This module also have functions for link files, globbing, etc.
config_out = esm_runscripts.filedicts.copy_files(config)
assert os.path.exists(
"/some/dummy/location/expid/run_18500101-18501231/work/unit.24"
)