Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
- import unittest
- add unittest to requirements
- add more test examples.
  • Loading branch information
Carsten Fortmann-Grote committed Mar 22, 2024
1 parent 91a332b commit 20425fa
Showing 1 changed file with 74 additions and 20 deletions.
94 changes: 74 additions & 20 deletions tests/test_template.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,89 @@
#!/usr/bin/env python
"""Tests for `template` package."""

import unittest
import os
import sys
import shutil
import pytest
from click.testing import CliRunner

from template import cli



def test_equal(response):
"""Test equality."""
class TemplateTest(unittest.TestCase):
""" A test class holding example tests using unittest. """

received = 1
expected = 1
def setUp(self) -> None:
""" Set up the test case. """

assert received == expected
# List where files and directories to be deleted are marked.
self._thrashcan = []

# A constant to be reused in any test function.
self._constant = "ABCD"

def test_lists_equal():
""" Test that two lists are equal."""
def tearDown(self) -> None:
""" Clean up after a test has finished."""

received = ["ACTG"]
expected = ["ACTG"]
assert received == expected

def test_cli():
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert 'python-template-package' in result.output
help_result = runner.invoke(cli.main, ['--help'])
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output
del self._constant

for item in self._thrashcan:
if os.path.isfile(item):
os.remove(item)
elif os.path.isdir(item):
shutil.rmtree(item)


def test_reusing_constant(self):
""" A test that reuses the test class constant"""

self.assertEqual(self._constant, "ABCD")

def test_equal(self):
"""Test equality."""

received = 1
expected = 1

self.assertEqual(received, expected)

def test_lists_equal(self):
""" Test that two lists are equal."""

received = ["ACTG"]
expected = ["ACTG"]

self.assertListEqual(received, expected)

def test_fails(self):
""" Example for a failing test."""

received = False

self.assertTrue(received)

@unittest.skip("Give me a good reason for skipping!")
def test_skipped_fails(self):
""" Example for a skipped failing test."""

received = False

self.assertTrue(received)

def test_cli(self):
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)

self.assertEqual(result.exit_code, 0)
self.assertIn('python-template-package' , result.output)

help_result = runner.invoke(cli.main, ['--help'])
self.assertEqual(help_result.exit_code, 0)
self.assertIn('--help Show this message and exit.', help_result.output)


if __name__ == "__main__":
unittest.main()

0 comments on commit 20425fa

Please sign in to comment.