Skip to content

Commit

Permalink
fix(test): test local config last, since it has side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise authored and roedoejet committed Oct 29, 2021
1 parent e4bccdc commit 86d8220
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
21 changes: 15 additions & 6 deletions g2p/tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from g2p.tests.test_transducer import TransducerTest
from g2p.tests.test_unidecode_transducer import UnidecodeTransducerTest
from g2p.tests.test_utils import UtilsTest
from g2p.tests.test_z_local_config import LocalConfigTest

# Deliberately left out:
# from g2p.tests.test_doctor_expensive import ExpensiveDoctorTest
Expand Down Expand Up @@ -66,21 +67,29 @@
]
]

DEV_TESTS = TRANSDUCER_TESTS + MAPPINGS_TESTS + LANGS_TESTS + INTEGRATION_TESTS
# LocalConfigTest has to get run last, to avoid interactions with other test
# cases, since it has side effects on the global database
LAST_DEV_TEST = [
LOADER.loadTestsFromTestCase(test) for test in [
LocalConfigTest,
]
]

DEV_TESTS = TRANSDUCER_TESTS + MAPPINGS_TESTS + LANGS_TESTS + INTEGRATION_TESTS + LAST_DEV_TEST


def run_tests(suite):
''' Decide which Test Suite to run
'''
if suite == 'all':
suite = LOADER.discover(os.path.dirname(__file__))
if suite == 'trans':
elif suite == 'trans':
suite = TestSuite(TRANSDUCER_TESTS)
if suite == 'langs':
elif suite == 'langs':
suite = TestSuite(LANGS_TESTS)
if suite == 'mappings':
elif suite == 'mappings':
suite = TestSuite(MAPPINGS_TESTS)
if suite == 'integ':
elif suite == 'integ':
suite = TestSuite(INTEGRATION_TESTS)
elif suite == 'dev':
suite = TestSuite(DEV_TESTS)
Expand All @@ -89,7 +98,7 @@ def run_tests(suite):
LOGGER.error("Please specify a test suite to run: i.e. 'dev' or 'all'")
else:
return runner.run(suite)



if __name__ == "__main__":
Expand Down
13 changes: 0 additions & 13 deletions g2p/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from g2p.app import APP
from g2p.cli import convert, doctor, generate_mapping, scan, update
from g2p.log import LOGGER
from g2p.tests.public import PUBLIC_DIR
from g2p.tests.public.data import __file__ as data_dir


Expand Down Expand Up @@ -225,18 +224,6 @@ def test_generate_mapping_errors(self):
"Non-existent out-dir must be reported as error",
)

def test_local_config(self):
config_path = os.path.join(PUBLIC_DIR, "mappings", "test.yaml")
result = self.runner.invoke(
convert,
["bbbb", "local-config-in", "local-config-out", "--config", config_path,],
)
self.assertIn("aaaa", result.stdout)
result = self.runner.invoke(
convert, ["b", "local-config-in", "eng-ipa", "--config", config_path,],
)
self.assertIn("ɑ", result.stdout)


if __name__ == "__main__":
main()
40 changes: 40 additions & 0 deletions g2p/tests/test_z_local_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3

"""
Test that the --config switch to g2p convert works
This test modifies the g2p database in memory, so it's important that it get
run last, in order to avoid changing the results of other unit test cases.
We accomplish that in two ways:
- in "./run.py dev", it gets appended after all the other tests, explicitly.
- the file name has a "z" so it sorts last when "./run.py all" uses LOADER.discover()
"""

from unittest import main, TestCase
import os

from g2p.app import APP
from g2p.cli import convert
from g2p.tests.public import PUBLIC_DIR


class LocalConfigTest(TestCase):
def setUp(self):
self.runner = APP.test_cli_runner()

def test_local_config(self):
config_path = os.path.join(PUBLIC_DIR, "mappings", "test.yaml")
result = self.runner.invoke(
convert,
["bbbb", "local-config-in", "local-config-out", "--config", config_path,],
)
self.assertIn("aaaa", result.stdout)
result = self.runner.invoke(
convert, ["b", "local-config-in", "eng-ipa", "--config", config_path,],
)
self.assertIn("ɑ", result.stdout)


if __name__ == "__main__":
main()

0 comments on commit 86d8220

Please sign in to comment.