Skip to content

Commit

Permalink
Added new test file. Fixed travis to run all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanheerdegen committed Dec 6, 2019
1 parent 0b78a66 commit 280abc9
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/test_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import os
from pathlib import Path
import shutil

import pdb
import pytest
import yaml

import payu

from payu.laboratory import Laboratory

from common import cd, make_random_file, get_manifests, tmpdir, ctrldir, labdir, workdir
from common import config, sweep_work, payu_init, payu_setup
from common import write_config, make_exe, make_inputs, make_restarts, make_all_files

verbose = True

def setup_module(module):
"""
Put any test-wide setup code in here, e.g. creating test files
"""
if verbose:
print("setup_module module:%s" % module.__name__)

# Should be taken care of by teardown, in case remnants lying around
try:
shutil.rmtree(tmpdir)
except FileNotFoundError:
pass

try:
tmpdir.mkdir()
labdir.mkdir()
ctrldir.mkdir()
except Exception as e:
print(e)

write_config()


def teardown_module(module):
"""
Put any test-wide teardown code in here, e.g. removing test outputs
"""
if verbose:
print("teardown_module module:%s" % module.__name__)

try:
shutil.rmtree(tmpdir)
print('removing tmp')
except Exception as e:
print(e)


def test_laboratory():

# Test instantiating a Laboratory object
with cd(ctrldir):
lab = Laboratory(None, None, None)

assert(Path(lab.basepath).parts[0] == '..')
assert(Path(lab.basepath).parts[2] == 'lab')

# Set a PROJECT env variable to get reproducible paths
os.environ['PROJECT'] = 'x00'

# Repeat, but remove shortpath definition
# in config, so will fall through to default
# depending on platform
del(config['shortpath'])
write_config()
with cd(ctrldir):
lab = Laboratory(None, None, None)

shortpath = '.'
for path in ['/short', '/scratch']:
if Path(path).exists():
shortpath = path
break

# pdb.set_trace()

assert(Path(lab.basepath).parents[2] == Path(shortpath))
assert(Path(lab.basepath).parts[2] == os.environ['PROJECT'])
assert(Path(lab.basepath).parts[-1] == 'lab')

0 comments on commit 280abc9

Please sign in to comment.