Skip to content

Commit

Permalink
Stop tests from depending on mkcodes installation.
Browse files Browse the repository at this point in the history
By using click's CliRunner for tests the test suite no longer depends on
having 'mkcodes' in the PATH.
  • Loading branch information
ryneeverett committed Aug 4, 2020
1 parent 2e64985 commit 18aabb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
3 changes: 0 additions & 3 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ let
pkgs.python3Packages.click
];
checkInputs = testDependencies;

# FIXME
doCheck = false;
};
in
pkgs.mkShell {
Expand Down
31 changes: 17 additions & 14 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import shutil
import textwrap
import unittest
import subprocess

import click.testing

import mkcodes


class TestBase(unittest.TestCase):
Expand All @@ -13,8 +16,9 @@ def tearDown(self):

@classmethod
def call(cls, *flags, inputfile='tests/data/some.md'):
subprocess.call([
'mkcodes', '--output', cls.outputfile] + list(flags) + [inputfile])
runner = click.testing.CliRunner()
runner.invoke(mkcodes.main,
['--output', cls.outputfile] + list(flags) + [inputfile])

def assertFileEqual(self, filename, expected):
with open(filename, 'r') as output:
Expand Down Expand Up @@ -67,8 +71,8 @@ def _output_path_exists(path):
return os.path.exists(os.path.join('tests/output', path))

@classmethod
def call(cls, **kwargs):
super().call('--github', **kwargs)
def call(cls, *args, **kwargs):
super().call('--github', *args, **kwargs)

def test_file(self):
self.call()
Expand All @@ -84,17 +88,16 @@ def test_directory(self):
self.assertTrue(self._output_path_exists('output.py'))

def test_directory_recursive(self):
subprocess.call([
'mkcodes', '--output', 'tests/output/{name}.py', '--github',
'tests/data'])
self.call(
'--output', 'tests/output/{name}.py', '--github', 'tests/data')
self.assertTrue(self._output_path_exists('some.py'))
self.assertTrue(self._output_path_exists('other.py'))
self.assertTrue(self._output_path_exists('nest/deep.py'))

def test_multiple(self):
subprocess.call([
'mkcodes', '--output', 'tests/output/{name}.py', '--github',
'tests/data/some.md', 'tests/data/other.md'])
self.call(
'--output', 'tests/output/{name}.py', '--github',
'tests/data/some.md', 'tests/data/other.md')
self.assertOutputFileEqual('some.py', """\
bar = False
Expand All @@ -107,9 +110,9 @@ def test_multiple(self):
self.assertFalse(self._output_path_exists('nest/deep.py'))

def test_unexistant_output_directory(self):
subprocess.call([
'mkcodes', '--output', 'tests/output/unexistant/{name}.py',
'--github', 'tests/data/some.md'])
self.call(
'--output', 'tests/output/unexistant/{name}.py',
'--github', 'tests/data/some.md')
self.assertOutputFileEqual('unexistant/some.py', """\
bar = False
Expand Down

0 comments on commit 18aabb5

Please sign in to comment.