Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed Mar 1, 2023
1 parent 0e17b0e commit 908f7f5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ dependencies = { file = "requirements.txt" }

[tool.setuptools.packages.find]
where = ["src"]
exclude = ["tests*"]
1 change: 1 addition & 0 deletions src/pger/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
MAIN = '__main__.py'
INIT = '__init__.py'
TEMPLATES = 'templates'
CONFTEST = 'conftest.py'

templates = Path(os.path.join(os.path.dirname(__file__), TEMPLATES))
15 changes: 12 additions & 3 deletions src/pger/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def __init__(self, user, repo, package, output=None):
self.output = Path(os.path.abspath(output) if output else repo)
self.output.mkdir(parents=True, exist_ok=True)
self.src = self.output / 'src'
(self.src / 'templates').mkdir(parents=True, exist_ok=True)
(self.src / package / const.TEMPLATES).mkdir(parents=True, exist_ok=True)
self.tests = self.src / 'tests'
self.workflows = self.output / '.github/workflows'
self.workflows.mkdir(parents=True, exist_ok=True)
self.pkg = self.src / package
Expand Down Expand Up @@ -52,15 +53,15 @@ def update(self):
)

def main(self):
(self.pkg / '__main__.py').write_text(dedent(f"""
(self.pkg / const.MAIN).write_text(dedent(f"""
from {self.package} import main
if __name__ == '__main__':
main()
""").lstrip())

def init(self):
(self.pkg / '__init__.py').write_text(dedent(f"""
(self.pkg / const.INIT).write_text(dedent(f"""
__title__ = '{self.repo}'
__author__ = '{self.user}'
__version__ = '0.0.1'
Expand All @@ -76,6 +77,13 @@ def main():
parser.parse_args()
""").lstrip())

def gen_tests(self):
self.tests.mkdir(parents=True, exist_ok=True)
(self.tests / const.INIT).write_text('')
(self.tests / const.CONFTEST).write_text(
(const.templates / const.CONFTEST).read_text()
)

def generate(self):
self.manifest()
self.pyproject()
Expand All @@ -86,4 +94,5 @@ def generate(self):
self.update()
self.main()
self.init()
self.gen_tests()
return self.output
6 changes: 6 additions & 0 deletions src/pger/templates/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture
def data():
return {'pytest': 'fixture'}
1 change: 1 addition & 0 deletions src/pger/templates/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ dependencies = {{ file = "requirements.txt" }}

[tool.setuptools.packages.find]
where = ["src"]
exclude = ["tests*"]
Empty file added src/tests/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture
def data():
return {'pytest': 'fixture'}

0 comments on commit 908f7f5

Please sign in to comment.