-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds PopperTest class and
popper versoin
test (#803)
Adds a PopperTest class that other unit tests can derive from in order to make use of generic testing functionality. Currently this contains a `mk_repo()` function that takes care of initializing a git repo with a `README` file in it. In addition, a test for the `popper version` command has been added that makes use of Click's unit testing features that allow to test CLI functionality. This will eventually replace the pipeline in the `ci/` folder.
- Loading branch information
1 parent
61c514c
commit d91d11d
Showing
6 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from click.testing import CliRunner | ||
import popper.commands.cmd_version as version | ||
import unittest | ||
from test_common import PopperTest | ||
from popper import __version__ as version_value | ||
|
||
|
||
class TestCommandVersion(PopperTest): | ||
|
||
def test_version(self): | ||
|
||
with self.assertLogs('popper') as test: | ||
runner = CliRunner() | ||
result = runner.invoke(version.cli) | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
self.assertTrue(version_value in test.output[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import sys | ||
import shutil | ||
import contextlib | ||
import subprocess | ||
import tempfile | ||
import git | ||
import unittest | ||
|
||
FIXDIR = f'{os.path.dirname(os.path.realpath(__file__))}/fixtures' | ||
|
||
|
||
class PopperTest(unittest.TestCase): | ||
|
||
def mk_repo(self): | ||
"""creates a test repo in a random temp file. Equivalent to: | ||
REPODIR=/tmp/<random> | ||
mkdir $REPODIR | ||
cd $REPODIR | ||
git init | ||
touch README.md | ||
git add . | ||
git commit -m 'first commit' | ||
""" | ||
tempdir = tempfile.mkdtemp() | ||
repo = git.Repo.init(tempdir) | ||
readme = os.path.join(tempdir, 'README.md') | ||
open(readme, 'w').close() | ||
repo.index.add([readme]) | ||
repo.index.commit('first commit') | ||
return repo | ||
|
||
|
||
class PopperCommonTest(PopperTest): | ||
|
||
def test_mkrepo(self): | ||
|
||
repo = self.mk_repo() | ||
self.assertTrue(os.path.isdir(repo.working_tree_dir)) | ||
self.assertTrue(os.path.isfile( | ||
os.path.join(repo.working_tree_dir, 'README.md'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.