diff --git a/cat_win/tests/mocks/std.py b/cat_win/tests/mocks/std.py index fe44412f..5427b60c 100644 --- a/cat_win/tests/mocks/std.py +++ b/cat_win/tests/mocks/std.py @@ -5,6 +5,24 @@ import io # import re + +class OSAttyDefGen: + """ + generate a function to replace os.isatty() + """ + + @staticmethod + def get_def(mapping: dict): + """ + return a function that returns the mapping + """ + def isatty(no: int, *args, **kwargs) -> bool: + """ + return the mapped values + """ + return mapping.get(no, False) + return isatty + # ansi_escape_8bit = re.compile(r''' # (?: # either 7-bit C1, two bytes, ESC Fe (omitting CSI) # \x1B @@ -38,16 +56,6 @@ def fileno(self) -> int: return 1 -class StdOutMockIsAtty(io.StringIO): - """ - mock for atty stdout stream - """ - closed: bool = False - - def isatty(self) -> bool: - return True - - class StdInMockIter: """ mock for stdin stream iterable @@ -60,6 +68,9 @@ def __init__(self, mock: object) -> None: # def __iter__(self): # return self + def fileno(self) -> int: + return 0 + def __next__(self) -> str: if self.index < len(self.splitted_input_value)-1: self.index += 1 diff --git a/cat_win/tests/test_full.py b/cat_win/tests/test_full.py index 958698ca..bed21e8f 100644 --- a/cat_win/tests/test_full.py +++ b/cat_win/tests/test_full.py @@ -3,7 +3,7 @@ import os from cat_win import cat -from cat_win.tests.mocks.std import StdInMock, StdOutMock, StdOutMockIsAtty +from cat_win.tests.mocks.std import StdInMock, StdOutMock from cat_win.util.argparser import ArgParser from cat_win.util.holder import Holder # import sys @@ -205,7 +205,7 @@ def test_cat_output_full_show_wordcount(self): @patch('cat_win.cat.sys.argv', ['', test_file_path, 'trunc=0:0', '--UNIQUE', '--b64', '-?']) def test_cat_output_suggestions(self): - with patch('cat_win.cat.sys.stderr', new=StdOutMockIsAtty()) as fake_out: + with patch('cat_win.cat.sys.stderr', new=StdOutMock()) as fake_out: cat.main() self.assertIn("Unknown argument: '--UNIQUE'", fake_out.getvalue()) self.assertIn("Did you mean --unique", fake_out.getvalue())