Add test for quiet loading option
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
This commit is contained in:
parent
28b61587cf
commit
7d3eded902
1 changed files with 22 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Copyright 2019 Apex.AI, Inc.
|
# Copyright 2019 Apex.AI, Inc.
|
||||||
|
# Copyright 2020 Christophe Bedard
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -13,6 +14,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import contextlib
|
||||||
|
from io import StringIO
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -60,31 +63,43 @@ class TestProcessCommand(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.test_dir_path)
|
shutil.rmtree(self.test_dir_path)
|
||||||
|
|
||||||
def test_inspect_input_path(self) -> None:
|
def test_inspect_input_path(
|
||||||
|
self,
|
||||||
|
quiet: bool = False,
|
||||||
|
) -> None:
|
||||||
# Should find converted file under directory
|
# Should find converted file under directory
|
||||||
file_path, create_file = inspect_input_path(self.with_converted_file_dir, False)
|
file_path, create_file = inspect_input_path(self.with_converted_file_dir, False, quiet)
|
||||||
self.assertEqual(self.converted_file_path, file_path)
|
self.assertEqual(self.converted_file_path, file_path)
|
||||||
self.assertFalse(create_file)
|
self.assertFalse(create_file)
|
||||||
# Should find it but set it to be re-created
|
# Should find it but set it to be re-created
|
||||||
file_path, create_file = inspect_input_path(self.with_converted_file_dir, True)
|
file_path, create_file = inspect_input_path(self.with_converted_file_dir, True, quiet)
|
||||||
self.assertEqual(self.converted_file_path, file_path)
|
self.assertEqual(self.converted_file_path, file_path)
|
||||||
self.assertTrue(create_file)
|
self.assertTrue(create_file)
|
||||||
|
|
||||||
# Should fail to find converted file under directory
|
# Should fail to find converted file under directory
|
||||||
file_path, create_file = inspect_input_path(self.without_converted_file_dir, False)
|
file_path, create_file = inspect_input_path(self.without_converted_file_dir, False, quiet)
|
||||||
self.assertIsNone(file_path)
|
self.assertIsNone(file_path)
|
||||||
self.assertFalse(create_file)
|
self.assertFalse(create_file)
|
||||||
file_path, create_file = inspect_input_path(self.without_converted_file_dir, True)
|
file_path, create_file = inspect_input_path(self.without_converted_file_dir, True, quiet)
|
||||||
self.assertIsNone(file_path)
|
self.assertIsNone(file_path)
|
||||||
self.assertFalse(create_file)
|
self.assertFalse(create_file)
|
||||||
|
|
||||||
# Should accept any file path if it exists
|
# Should accept any file path if it exists
|
||||||
file_path, create_file = inspect_input_path(self.random_file_path, False)
|
file_path, create_file = inspect_input_path(self.random_file_path, False, quiet)
|
||||||
self.assertEqual(self.random_file_path, file_path)
|
self.assertEqual(self.random_file_path, file_path)
|
||||||
self.assertFalse(create_file)
|
self.assertFalse(create_file)
|
||||||
# Should set it to be re-created
|
# Should set it to be re-created
|
||||||
file_path, create_file = inspect_input_path(self.random_file_path, True)
|
file_path, create_file = inspect_input_path(self.random_file_path, True, quiet)
|
||||||
self.assertEqual(self.random_file_path, file_path)
|
self.assertEqual(self.random_file_path, file_path)
|
||||||
self.assertTrue(create_file)
|
self.assertTrue(create_file)
|
||||||
|
|
||||||
# TODO try with a trace directory
|
# TODO try with a trace directory
|
||||||
|
|
||||||
|
def test_inspect_input_path_quiet(self) -> None:
|
||||||
|
temp_stdout = StringIO()
|
||||||
|
with contextlib.redirect_stdout(temp_stdout):
|
||||||
|
# Just run the other test again
|
||||||
|
self.test_inspect_input_path(quiet=True)
|
||||||
|
# Shouldn't be any output
|
||||||
|
output = temp_stdout.getvalue()
|
||||||
|
self.assertEqual(0, len(output), f'was not quiet: "{output}"')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue