Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Jan 15, 2024
1 parent cca82c2 commit 3fa55b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
31 changes: 21 additions & 10 deletions cat_win/tests/mocks/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cat_win/tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_cat_output_full_show_wordcount(self):
@patch('cat_win.cat.sys.argv',
['<CAT>', 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())
Expand Down

0 comments on commit 3fa55b8

Please sign in to comment.