Skip to content

Commit

Permalink
use tempfile instead of custom test-output
Browse files Browse the repository at this point in the history
  • Loading branch information
selimb committed Dec 10, 2019
1 parent 2326e4d commit 2bd6ebb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Auto-generated from tests
test-output

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
15 changes: 5 additions & 10 deletions tests/test_mypy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shutil
import tempfile
import textwrap
import os
import unittest
Expand All @@ -10,8 +11,6 @@
# mypy not installed on pypy (see setup.py)
mypy_installed = False

HERE = os.path.dirname(__file__)
TEST_OUTPUT_DIR = os.path.join(HERE, "test-output")
MYPY_INI = """\
[mypy]
follow_imports = silent
Expand All @@ -25,21 +24,17 @@ class TestMypyPlugin(unittest.TestCase):

def setUp(self):
"""
Prepare a clean test directory at tests/test-output/test_mypy-{testname}.
Prepare a clean temporary test directory.
Also cd into it for the duration of the test to get simple filenames in mypy output.
"""
testname = self.id().split(".")[-1]
self.testdir = os.path.join(TEST_OUTPUT_DIR, f"test_mypy-{testname}")
if os.path.exists(self.testdir):
shutil.rmtree(self.testdir)
os.makedirs(self.testdir)
self.testdir = tempfile.mkdtemp()
self.old_cwd = os.getcwd()
os.chdir(self.testdir)

def tearDown(self):
os.chdir(self.old_cwd)

def mypy_test(self, contents: str, expected: str):
def assert_mypy_output(self, contents: str, expected: str):
"""
Run mypy and assert output matches ``expected``.
Expand All @@ -59,7 +54,7 @@ def mypy_test(self, contents: str, expected: str):
self.assertEqual(out.strip(), textwrap.dedent(expected).strip(), err_msg)

def test_basic(self):
self.mypy_test(
self.assert_mypy_output(
"""
from dataclasses import dataclass
import marshmallow as ma
Expand Down

0 comments on commit 2bd6ebb

Please sign in to comment.