Skip to content

Commit

Permalink
Fixes and test for test
Browse files Browse the repository at this point in the history
  • Loading branch information
thatch committed Mar 10, 2020
1 parent db6be67 commit b70036b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bowler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
# LICENSE file in the root directory of this source tree.

import importlib
import importlib.util
import logging
import os.path
import sys
import unittest
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -143,18 +146,17 @@ def run(codemod: str, argv: List[str]) -> None:
def test(codemod: str) -> None:
"""
Run the tests in the codemod file
"""
import unittest
import importlib.util
import os.path
"""

# TODO: Unify the import code between 'run' and 'test'
module_name_from_codemod = os.path.basename(codemod).replace(".py", "")
spec = importlib.util.spec_from_file_location(module_name_from_codemod, codemod)
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
suite = unittest.TestLoader().loadTestsFromModule(foo)

unittest.TextTestRunner().run(suite)
result = unittest.TextTestRunner().run(suite)
sys.exit(not result.wasSuccessful())


if __name__ == "__main__":
Expand Down
17 changes: 17 additions & 0 deletions bowler/tests/smoke-selftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
#
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.


from bowler.tests.lib import BowlerTestCase


class Tests(BowlerTestCase):
def test_pass(self):
pass

def test_fail(self):
assert False
12 changes: 12 additions & 0 deletions bowler/tests/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import io
import logging
import subprocess
import sys
from pathlib import Path
from unittest import TestCase
from unittest.mock import Mock
Expand Down Expand Up @@ -82,3 +84,13 @@ def test_check_ast(self):
)
self.assertTrue(any(isinstance(e, BadTransform) for e in query.exceptions))
mock_processor.assert_not_called()

def test_click_test(self):
proc = subprocess.run(
[sys.executable, "-m", "bowler", "test", "bowler/tests/smoke-selftest.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
self.assertIn("Ran 2 tests", proc.stderr)
self.assertEqual(1, proc.returncode)

0 comments on commit b70036b

Please sign in to comment.