1
1
import os
2
2
import pytest
3
- import shutil
4
- from pathlib import Path
5
-
6
- from cookiecutter import main
7
-
8
- CCDS_ROOT = Path (__file__ ).parents [1 ].resolve ()
9
-
10
-
11
- @pytest .fixture (scope = 'function' )
12
- def default_baked_project (tmpdir ):
13
- temp = tmpdir .mkdir ('data-project' )
14
- out_dir = Path (temp ).resolve ()
15
-
16
- main .cookiecutter (
17
- str (CCDS_ROOT ),
18
- no_input = True ,
19
- extra_context = {},
20
- output_dir = out_dir
21
- )
22
-
23
- # default project name is project_name
24
- yield out_dir / 'project_name'
25
-
26
- # cleanup after
27
- shutil .rmtree (out_dir )
28
-
29
-
30
- def test_readme (default_baked_project ):
31
- readme_path = default_baked_project / 'README.md'
32
-
33
- assert readme_path .exists ()
34
- assert no_curlies (readme_path )
35
-
36
-
37
- def test_license (default_baked_project ):
38
- license_path = default_baked_project / 'LICENSE'
39
-
40
- assert license_path .exists ()
41
- assert no_curlies (license_path )
42
-
43
-
44
- def test_requirements (default_baked_project ):
45
- reqs_path = default_baked_project / 'requirements.txt'
46
-
47
- assert reqs_path .exists ()
48
- assert no_curlies (reqs_path )
49
-
50
-
51
- def test_makefile (default_baked_project ):
52
- makefile_path = default_baked_project / 'Makefile'
53
-
54
- assert makefile_path .exists ()
55
- assert no_curlies (makefile_path )
56
-
57
-
58
- def test_folders (default_baked_project ):
59
- expected_dirs = [
60
- 'data' ,
61
- 'data/external' ,
62
- 'data/interim' ,
63
- 'data/processed' ,
64
- 'data/raw' ,
65
- 'docs' ,
66
- 'models' ,
67
- 'notebooks' ,
68
- 'references' ,
69
- 'reports' ,
70
- 'reports/figures' ,
71
- 'src' ,
72
- 'src/data' ,
73
- 'src/features' ,
74
- 'src/models' ,
75
- 'src/visualization' ,
76
- ]
77
-
78
- ignored_dirs = [
79
- str (default_baked_project )
80
- ]
81
-
82
- abs_expected_dirs = [str (default_baked_project / d ) for d in expected_dirs ]
83
- abs_dirs , _ , _ = list (zip (* os .walk (default_baked_project )))
84
- assert len (set (abs_expected_dirs + ignored_dirs ) - set (abs_dirs )) == 0
3
+ from subprocess import check_output
4
+ from conftest import system_check
85
5
86
6
87
7
def no_curlies (filepath ):
@@ -100,3 +20,94 @@ def no_curlies(filepath):
100
20
101
21
template_strings_in_file = [s in data for s in template_strings ]
102
22
return not any (template_strings_in_file )
23
+
24
+
25
+ @pytest .mark .usefixtures ("default_baked_project" )
26
+ class TestCookieSetup (object ):
27
+ def test_project_name (self ):
28
+ project = self .path
29
+ if pytest .param .get ('project_name' ):
30
+ name = system_check ('DrivenData' )
31
+ assert project .name == name
32
+ else :
33
+ assert project .name == 'project_name'
34
+
35
+ def test_author (self ):
36
+ setup_ = self .path / 'setup.py'
37
+ args = ['python' , setup_ , '--author' ]
38
+ p = check_output (args ).decode ('ascii' ).strip ()
39
+ if pytest .param .get ('author_name' ):
40
+ assert p == 'DrivenData'
41
+ else :
42
+ assert p == 'Your name (or your organization/company/team)'
43
+
44
+ def test_readme (self ):
45
+ readme_path = self .path / 'README.md'
46
+ assert readme_path .exists ()
47
+ assert no_curlies (readme_path )
48
+ if pytest .param .get ('project_name' ):
49
+ with open (readme_path ) as fin :
50
+ assert 'DrivenData' == next (fin ).strip ()
51
+
52
+ def test_setup (self ):
53
+ setup_ = self .path / 'setup.py'
54
+ args = ['python' , setup_ , '--version' ]
55
+ p = check_output (args ).decode ('ascii' ).strip ()
56
+ assert p == '0.1.0'
57
+
58
+ def test_license (self ):
59
+ license_path = self .path / 'LICENSE'
60
+ assert license_path .exists ()
61
+ assert no_curlies (license_path )
62
+
63
+ def test_license_type (self ):
64
+ setup_ = self .path / 'setup.py'
65
+ args = ['python' , setup_ , '--license' ]
66
+ p = check_output (args ).decode ('ascii' ).strip ()
67
+ if pytest .param .get ('open_source_license' ):
68
+ assert p == 'BSD-3'
69
+ else :
70
+ assert p == 'MIT'
71
+
72
+ def test_requirements (self ):
73
+ reqs_path = self .path / 'requirements.txt'
74
+ assert reqs_path .exists ()
75
+ assert no_curlies (reqs_path )
76
+ if pytest .param .get ('python_interpreter' ):
77
+ with open (reqs_path ) as fin :
78
+ lines = list (map (lambda x : x .strip (), fin .readlines ()))
79
+ assert 'pathlib2' in lines
80
+
81
+ def test_makefile (self ):
82
+ makefile_path = self .path / 'Makefile'
83
+ assert makefile_path .exists ()
84
+ assert no_curlies (makefile_path )
85
+
86
+ def test_folders (self ):
87
+ expected_dirs = [
88
+ 'data' ,
89
+ 'data/external' ,
90
+ 'data/interim' ,
91
+ 'data/processed' ,
92
+ 'data/raw' ,
93
+ 'docs' ,
94
+ 'models' ,
95
+ 'notebooks' ,
96
+ 'references' ,
97
+ 'reports' ,
98
+ 'reports/figures' ,
99
+ 'src' ,
100
+ 'src/data' ,
101
+ 'src/features' ,
102
+ 'src/models' ,
103
+ 'src/visualization' ,
104
+ ]
105
+
106
+ ignored_dirs = [
107
+ str (self .path )
108
+ ]
109
+
110
+ abs_expected_dirs = [str (self .path / d ) for d in expected_dirs ]
111
+ abs_dirs , _ , _ = list (zip (* os .walk (self .path )))
112
+ assert len (set (abs_expected_dirs + ignored_dirs ) - set (abs_dirs )) == 0
113
+
0 commit comments