diff options
author | Matthew Blecker <matthewb@chromium.org> | 2021-08-26 13:59:01 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-27 01:41:46 +0000 |
commit | 352e821faab88e59f2e60df23b671564de595827 (patch) | |
tree | 25a028e4da102089d2bc6b7a95b7e9c66771faad /util | |
parent | bc1eadcd1df76ee9d698a3ce531b422654760726 (diff) | |
download | chrome-ec-352e821faab88e59f2e60df23b671564de595827.tar.gz |
ec3po: Update unittests to use ec3po.<module> import paths.
run_tests.sh no longer uses the Python unittest module's discovery
functionality, which was forcing util/ec3po/ subdir to be directly in
sys.path as a top-level module location, which is inconsistent with how
ec3po modules are used outside of the tests.
run_tests.sh no longer auto-discovers *_unittest.py files, instead they
are individually listed as ec3po.<name>_unittest modules. It would be
straightforward to implement test module autodiscovery, but probably
isn't worth the complexity.
BRANCH=none
BUG=chromium:1031705,b:174894072,b:197618562
TEST=Within chroot, ran ./runtests.sh from within util/ec3po/ directory.
Within chroot, ran ~/trunk/src/platform/ec/util/ec3po/run_tests.sh from
a different directory.
Verified use of the files-under-test (as opposed to the files installed
in site-packages/) by adding broken code to console.py and then
re-running both invoctions above. Both then failed as intended.
Change-Id: I40c180f1d66a4d3befc548f4d763357e6cc24201
Signed-off-by: Matthew Blecker <matthewb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3123835
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'util')
-rwxr-xr-x | util/ec3po/console_unittest.py | 8 | ||||
-rwxr-xr-x | util/ec3po/interpreter_unittest.py | 6 | ||||
-rwxr-xr-x | util/ec3po/run_tests.sh | 12 |
3 files changed, 16 insertions, 10 deletions
diff --git a/util/ec3po/console_unittest.py b/util/ec3po/console_unittest.py index 1555a92bc5..912ebfb26d 100755 --- a/util/ec3po/console_unittest.py +++ b/util/ec3po/console_unittest.py @@ -1078,7 +1078,7 @@ class TestConsoleCompatibility(unittest.TestCase): tempfile.TemporaryFile(), mock_pipe_end_0, mock_pipe_end_1, "EC") - @mock.patch('console.Console.CheckForEnhancedECImage') + @mock.patch('ec3po.console.Console.CheckForEnhancedECImage') def test_ActAsPassThruInNonEnhancedMode(self, mock_check): """Verify we simply pass everything thru to non-enhanced ECs. @@ -1124,7 +1124,7 @@ class TestConsoleCompatibility(unittest.TestCase): CheckInputBuffer(self, b'') CheckInputBufferPosition(self, 0) - @mock.patch('console.Console.CheckForEnhancedECImage') + @mock.patch('ec3po.console.Console.CheckForEnhancedECImage') def test_TransitionFromNonEnhancedToEnhanced(self, mock_check): """Verify that we transition correctly to enhanced mode. @@ -1185,7 +1185,7 @@ class TestConsoleCompatibility(unittest.TestCase): # Verify all of the calls. self.console.cmd_pipe.send.assert_has_calls(expected_calls) - @mock.patch('console.Console.CheckForEnhancedECImage') + @mock.patch('ec3po.console.Console.CheckForEnhancedECImage') def test_TransitionFromEnhancedToNonEnhanced(self, mock_check): """Verify that we transition correctly to non-enhanced mode. @@ -1362,7 +1362,7 @@ class TestOOBMConsoleCommands(unittest.TestCase): mock_pipe_end_0, mock_pipe_end_1, "EC") self.console.oobm_queue = mock.MagicMock() - @mock.patch('console.Console.CheckForEnhancedECImage') + @mock.patch('ec3po.console.Console.CheckForEnhancedECImage') def test_InterrogateCommand(self, mock_check): """Verify that 'interrogate' command works as expected. diff --git a/util/ec3po/interpreter_unittest.py b/util/ec3po/interpreter_unittest.py index 107800dd38..a243177b1b 100755 --- a/util/ec3po/interpreter_unittest.py +++ b/util/ec3po/interpreter_unittest.py @@ -54,7 +54,7 @@ class TestEnhancedECBehaviour(unittest.TestCase): log_level=logging.DEBUG, name="EC") - @mock.patch('interpreter.os') + @mock.patch('ec3po.interpreter.os') def test_HandlingCommandsThatProduceNoOutput(self, mock_os): """Verify that the Interpreter correctly handles non-output commands. @@ -119,7 +119,7 @@ class TestEnhancedECBehaviour(unittest.TestCase): # Finally, verify that the appropriate writes were actually sent to the EC. self.ec_uart_pty.assert_has_calls(expected_ec_calls) - @mock.patch('interpreter.os') + @mock.patch('ec3po.interpreter.os') def test_CommandRetryingOnError(self, mock_os): """Verify that commands are retried if an error is encountered. @@ -208,7 +208,7 @@ class TestEnhancedECBehaviour(unittest.TestCase): # Verify that PackCommand() was called. self.itpr.PackCommand.assert_not_called() - @mock.patch('interpreter.os') + @mock.patch('ec3po.interpreter.os') def test_KeepingTrackOfInterrogation(self, mock_os): """Verify that the interpreter can track the state of the interrogation. diff --git a/util/ec3po/run_tests.sh b/util/ec3po/run_tests.sh index 09e1a545d0..ba513abe30 100755 --- a/util/ec3po/run_tests.sh +++ b/util/ec3po/run_tests.sh @@ -4,6 +4,12 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# Discover all the unit tests in the ec3po directory and run them. -python3 -m unittest discover -b -s util/ec3po/ -p "*_unittest.py" \ - && touch util/ec3po/.tests-passed +set -e + +my_dir="$(realpath -e -- "$(dirname -- "$0")")" +parent_dir="$(realpath -e -- "$my_dir/..")" + +PYTHONPATH="$parent_dir" python3 -s -m unittest \ + ec3po.console_unittest \ + ec3po.interpreter_unittest \ + && touch -- "$my_dir/.tests-passed" |