Skip to content

Commit

Permalink
added edge case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Dec 13, 2024
1 parent 233372b commit 5969384
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cat_win/tests/src/service/helper/test_iohelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def test_get_newline(self):
self.assertEqual(IoHelper.get_newline(test_file_path_empty, 'x'), 'x')
self.assertEqual(IoHelper.get_newline(test_file_path_oneline, 'x'), 'x')

def test_get_newline_error(self):
self.assertEqual(IoHelper.get_newline('randomFileThatHopefullyDoesNotExistWithWeirdCharsForSafety*!?\\/:<>|', 'DEFAULT'), 'DEFAULT')

def test_get_stdin_content_oneline(self):
stdin_mock.set_content('hello\nworld')
self.assertEqual(''.join(IoHelper.get_stdin_content(True)), 'hello')
Expand Down
14 changes: 14 additions & 0 deletions cat_win/tests/src/service/helper/test_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ def test_pbar_atty(self):
self.assertIn('XX', fake_out.getvalue())
self.assertNotIn('\b \b', fake_out.getvalue())

@patch('os.isatty', OSAttyDefGen.get_def({1: True}))
@patch('cat_win.src.service.helper.progressbar.CURSOR_VISIBLE', '')
@patch('cat_win.src.service.helper.progressbar.CURSOR_INVISIBLE', '')
@patch('cat_win.src.service.helper.progressbar.PBar.COLOR_DONE', '')
@patch('cat_win.src.service.helper.progressbar.PBar.COLOR_MISSING', '')
@patch('cat_win.src.service.helper.progressbar.PBar.COLOR_RESET', '')
def test_pbar_atty_out_of_bound(self):
with patch('sys.stdout', new=StdOutMock()) as fake_out:
with PBar(2, prefix='', suffix='',
length=2, fill_l='X', fill_r='_').init() as p_bar:
for i in range(-1, 4):
p_bar(i)
self.assertEqual(fake_out.getvalue(), '\r XX 100.0% \r __ 0.0% \r X_ 50.0% \r XX 100.0% \r XX 100.0% \n')

@patch('os.isatty', OSAttyDefGen.get_def({1: True}))
def test_pbar_atty_erase(self):
with patch('sys.stdout', new=StdOutMock()) as fake_out:
Expand Down

0 comments on commit 5969384

Please sign in to comment.