Exemple #1
0
 def test__write_Should_CallExpected_When_NoTtyButForce(self, print_patch, stderr_patch, *patches):
     stderr_patch.isatty.return_value = False
     term = Terminal(13, create=True)
     term.current = 0
     term.write(3, force=True)
     self.assertEqual(len(print_patch.mock_calls), 2)
     self.assertEqual(term.current, 1)
Exemple #2
0
 def test__write_Should_CallExpected_When_Notty(self, print_patch, stderr_patch, *patches):
     stderr_patch.isatty.return_value = False
     term = Terminal(13, create=True)
     term.current = 0
     term.write(3)
     print_patch.assert_not_called()
     self.assertEqual(term.current, 0)
Exemple #3
0
 def test__init__Should_SetAttributes_When_Called(self, create_patch, *patches):
     term = Terminal(4)
     self.assertEqual(term.config, {})
     self.assertEqual(term.current, 0)
     self.assertEqual(term.terminal, create_patch.return_value)
Exemple #4
0
 def test__show_cursor_Should_CallExpected_When_NoAtty(self, cursor_patch, stderr_patch, *patches):
     stderr_patch.isatty.return_value = False
     term = Terminal(3, create=False)
     term.show_cursor()
     cursor_patch.show.assert_not_called()
Exemple #5
0
 def test__hide_cursor_Should_CallExpected_When_Called(self, cursor_patch, stderr_patch, *patches):
     stderr_patch.isatty.return_value = True
     term = Terminal(3, create=False)
     term.hide_cursor()
     cursor_patch.hide.assert_called_once_with()
Exemple #6
0
 def test__move_up_Should_ReturnExpected_When_Called(self, up_patch, *patches):
     term = Terminal(13, create=False)
     term.current = 12
     result = term.move_up(7)
     self.assertEqual(result, up_patch.return_value)
     self.assertEqual(term.current, 7)
Exemple #7
0
 def test__create_Should_CallAndReturnExpected_When_ProgressBar(self, create_progress_bars_patch, *patches):
     term = Terminal(10, create=False, config={'progress_bar': {'total': 100, 'count_regex': '--regex--'}})
     result = term.create(10)
     self.assertEqual(result, create_progress_bars_patch.return_value)
Exemple #8
0
 def test__create_progress_bars_Should_ReturnExpected_When_TotalIsInt(self, *patches):
     term = Terminal(10, create=False, config={'progress_bar': {'total': 100, 'count_regex': '--regex--'}})
     result = term.create_progress_bars(10)
     self.assertTrue(len(result), 10)
Exemple #9
0
 def test__validate_config_Should_RaiseValueError_When_NotRequiredKeys(self, *patches):
     config = {'progress_bar': {'key1': 'value1'}}
     with self.assertRaises(ValueError):
         Terminal(4, config=config, create=False)
Exemple #10
0
 def test__write_lines_Should_CallExpected_When_AddDuration(self, write_patch, *patches):
     trmnl = Terminal(3, durations={'0': 'd1', '1': 'd2', '2': 'd3'})
     trmnl.current = 0
     trmnl.write_lines(add_duration=True)
     self.assertEqual(len(write_patch.mock_calls), 3)
Exemple #11
0
 def test__write_lines_Should_CallExpected_When_Called(self, write_patch, *patches):
     term = Terminal(3)
     term.write_lines()
     self.assertEqual(len(write_patch.mock_calls), 3)
Exemple #12
0
 def test__write_line_Should_CallExpected_When_Called(self, write_patch, *patches):
     term = Terminal(13, create=True)
     term.write_line(4, '--some-text--')
     write_patch.assert_called_once_with(4)
Exemple #13
0
 def test__create_Should_CallAndReturnExpected_When_NoProgressBar(self, create_status_lines_patch, *patches):
     term = Terminal(10, create=False)
     result = term.create(10)
     self.assertEqual(result, create_status_lines_patch.return_value)
Exemple #14
0
 def test__validate_lines_Should_RaiseValueError_When_LinesLessThanZero(self, *patches):
     with self.assertRaises(ValueError):
         Terminal(-1)
Exemple #15
0
 def test__reset_Should_CallExpected_When_Called(self, *patches):
     term = Terminal(3)
     term.reset(1)
     term.terminal[1].reset.assert_called_once()
Exemple #16
0
 def test__validate_lines_Should_RaiseValueError_When_GreaterThanMaxLines(self, *patches):
     with self.assertRaises(ValueError):
         Terminal(MAX_LINES + 1)
Exemple #17
0
 def test__get_move_char_Should_ReturnExpected_When_MovingUp(self, move_up_patch, *patches):
     move_up_patch.return_value = Mock(), Mock()
     term = Terminal(13, create=False)
     term.current = 12
     result = term.get_move_char(7)
     self.assertEqual(result, move_up_patch.return_value)
Exemple #18
0
 def test__validate_config_Should_RaiseValueError_When_InvalidProgressBarTotal(self, *patches):
     config = {'progress_bar': {'total': [], 'count_regex': '-regex-'}}
     with self.assertRaises(ValueError):
         Terminal(4, config=config, create=False)
Exemple #19
0
 def test__get_move_char_Should_ReturnExpected_When_NotMoving(self, move_down_patch, *patches):
     term = Terminal(13, create=False)
     term.current = 2
     result = term.get_move_char(2)
     self.assertEqual(result, '')
Exemple #20
0
 def test__create_status_lines_Should_ReturnExpected_When_Called(self, *patches):
     term = Terminal(10, create=False)
     result = term.create_status_lines(10)
     self.assertTrue(len(result), 10)
Exemple #21
0
def main():
    print('generating random sentences...')
    count = 15
    docgen = DocumentGenerator()
    terminal = Terminal(count)
    terminal.write_lines()
    terminal.hide_cursor()
    for _ in range(800):
        index = random.randint(0, count - 1)
        terminal.write_line(index, docgen.sentence())
        time.sleep(.01)
    terminal.write_lines(force=True)
    terminal.show_cursor()