mirror of
https://github.com/wassname/cookiecutter-data-science.git
synced 2026-06-27 22:06:50 +08:00
08d357c5fa
Official support for Python 2 ended on Jan 1, 2020 (see https://www.python.org/doc/sunset-python-2/ for more info). This change does not prevent anybody from using Python 2, but we should not be encouraging new projects to use it.
110 lines
3.1 KiB
Python
110 lines
3.1 KiB
Python
import os
|
|
import pytest
|
|
from subprocess import check_output
|
|
from conftest import system_check
|
|
|
|
|
|
def no_curlies(filepath):
|
|
""" Utility to make sure no curly braces appear in a file.
|
|
That is, was Jinja able to render everything?
|
|
"""
|
|
with open(filepath, 'r') as f:
|
|
data = f.read()
|
|
|
|
template_strings = [
|
|
'{{',
|
|
'}}',
|
|
'{%',
|
|
'%}'
|
|
]
|
|
|
|
template_strings_in_file = [s in data for s in template_strings]
|
|
return not any(template_strings_in_file)
|
|
|
|
|
|
@pytest.mark.usefixtures("default_baked_project")
|
|
class TestCookieSetup(object):
|
|
def test_project_name(self):
|
|
project = self.path
|
|
if pytest.param.get('project_name'):
|
|
name = system_check('DrivenData')
|
|
assert project.name == name
|
|
else:
|
|
assert project.name == 'project_name'
|
|
|
|
def test_author(self):
|
|
setup_ = self.path / 'setup.py'
|
|
args = ['python', setup_, '--author']
|
|
p = check_output(args).decode('ascii').strip()
|
|
if pytest.param.get('author_name'):
|
|
assert p == 'DrivenData'
|
|
else:
|
|
assert p == 'Your name (or your organization/company/team)'
|
|
|
|
def test_readme(self):
|
|
readme_path = self.path / 'README.md'
|
|
assert readme_path.exists()
|
|
assert no_curlies(readme_path)
|
|
if pytest.param.get('project_name'):
|
|
with open(readme_path) as fin:
|
|
assert 'DrivenData' == next(fin).strip()
|
|
|
|
def test_setup(self):
|
|
setup_ = self.path / 'setup.py'
|
|
args = ['python', setup_, '--version']
|
|
p = check_output(args).decode('ascii').strip()
|
|
assert p == '0.1.0'
|
|
|
|
def test_license(self):
|
|
license_path = self.path / 'LICENSE'
|
|
assert license_path.exists()
|
|
assert no_curlies(license_path)
|
|
|
|
def test_license_type(self):
|
|
setup_ = self.path / 'setup.py'
|
|
args = ['python', setup_, '--license']
|
|
p = check_output(args).decode('ascii').strip()
|
|
if pytest.param.get('open_source_license'):
|
|
assert p == 'BSD-3'
|
|
else:
|
|
assert p == 'MIT'
|
|
|
|
def test_requirements(self):
|
|
reqs_path = self.path / 'requirements.txt'
|
|
assert reqs_path.exists()
|
|
assert no_curlies(reqs_path)
|
|
|
|
def test_makefile(self):
|
|
makefile_path = self.path / 'Makefile'
|
|
assert makefile_path.exists()
|
|
assert no_curlies(makefile_path)
|
|
|
|
def test_folders(self):
|
|
expected_dirs = [
|
|
'data',
|
|
'data/external',
|
|
'data/interim',
|
|
'data/processed',
|
|
'data/raw',
|
|
'docs',
|
|
'models',
|
|
'notebooks',
|
|
'references',
|
|
'reports',
|
|
'reports/figures',
|
|
'src',
|
|
'src/data',
|
|
'src/features',
|
|
'src/models',
|
|
'src/visualization',
|
|
]
|
|
|
|
ignored_dirs = [
|
|
str(self.path)
|
|
]
|
|
|
|
abs_expected_dirs = [str(self.path / d) for d in expected_dirs]
|
|
abs_dirs, _, _ = list(zip(*os.walk(self.path)))
|
|
assert len(set(abs_expected_dirs + ignored_dirs) - set(abs_dirs)) == 0
|
|
|