Skip to content

Commit ea4186b

Browse files
authored
Merge pull request #184 from ocefpaf/test_mode
Test if mode is unique
2 parents da4023d + eec4088 commit ea4186b

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

test/test_cli.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from wof.wofpy_config import makedirs
9+
from wof.wofpy_config import cli, makedirs
1010

1111

1212
@pytest.fixture(scope='function')
@@ -32,10 +32,16 @@ def test_makedirs_overwrite_soft():
3232
assert _stat.st_ino == stat.st_ino
3333

3434

35-
@pytest.mark.skipif(sys.platform == 'win32',
36-
reason='st_ino does not work on Windows')
37-
def test_makedirs_overwrite_hard():
38-
_directory, _stat = mkdtemp().next()
39-
makedirs(_directory, overwrite='hard')
40-
stat = os.stat(_directory)
41-
assert _stat.st_ino != stat.st_ino
35+
36+
def test_cli_overwrite_hard():
37+
_directory, _ = mkdtemp().next()
38+
args = {
39+
'INDIR': _directory,
40+
'--mode': 'production',
41+
'--overwrite': 'hard'
42+
}
43+
cli(args)
44+
assert os.path.isdir(os.path.join(_directory, 'production_configs'))
45+
args.update({'--mode': 'development'})
46+
cli(args)
47+
assert not os.path.isdir(os.path.join(_directory, 'production_configs'))

wof/wofpy_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,21 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite='soft'):
6464
shutil.copy2(s, d)
6565

6666

67-
def main():
67+
def parse_args():
6868
args = docopt(__doc__, version='1.0.0')
69+
return args
70+
71+
72+
def cli(args):
6973
directory = args.get('INDIR')
7074
mode = args.get('--mode').lower()
75+
overwrite = args.get('--overwrite').lower()
76+
7177
if mode not in ['development', 'production']:
7278
raise ValueError(
7379
'Got mode: {!r}, expected development, or production.'.format(mode)
7480
)
75-
overwrite = args.get('--overwrite').lower()
81+
7682
if overwrite not in ['hard', 'soft']:
7783
raise ValueError(
7884
'Got overwrite: {!r}, expected hard or soft.'.format(overwrite)
@@ -89,5 +95,9 @@ def main():
8995
copytree(_CONFIG, _PRODUCTION, overwrite=overwrite)
9096

9197

98+
def main():
99+
args = parse_args()
100+
cli(args)
101+
92102
if __name__ == '__main__':
93103
main()

0 commit comments

Comments
 (0)