def test_width(self): """Width hard-coded""" manager = enlighten.Manager(width=100) ctr = manager.counter(total=100) self.assertEqual(len(ctr.format()), 100)
def __init__(self, total: int) -> None: self.mgr = enlighten.Manager() self.pending = self.mgr.counter(total=total, desc='Auditing', unit='tasks', color='gray', bar_format=self.bar_format) self.success = self.pending.add_subcounter('green') self.skipped = self.pending.add_subcounter('orange') self.failed = self.pending.add_subcounter('red') self.queued = 0 self.status = self.mgr.status_bar( status_format=self.status_format, queued=0, success=0, pending=0, skipped=0, failed=0, finished=0, todo=total, **{f'stage_{stage.name}': 0 for stage in CheckStage}) self._stage_count: Counter[CheckStage] = Counter()
def test_context_manager(self): mgr = enlighten.Manager(stream=self.tty.stdout, enabled=False) with mgr.counter(total=10, leave=False) as ctr: self.assertTrue(ctr in mgr.counters) ctr.update() self.assertFalse(ctr in mgr.counters)
def test_at_exit(self): tty = MockTTY() with mock.patch('enlighten.Terminal.reset') as reset: manager = enlighten.Manager(stream=tty.stdout, counter_class=MockCounter) term = manager.term # process_exit is False manager._at_exit() self.assertFalse(reset.called) # No output tty.stdout.write('X\n') self.assertEqual(tty.stdread.readline(), 'X\n') # process_exit is True, set_scroll False manager.process_exit = True manager.set_scroll = False manager._at_exit() self.assertFalse(reset.called) self.assertEqual(tty.stdread.readline(), term.move(25, 0) + term.cud1) # process_exit is True, set_scroll True manager.set_scroll = True manager._at_exit() self.assertEqual(reset.call_count, 1) self.assertEqual(tty.stdread.readline(), term.cud1) tty.close() manager._at_exit()
def test_set_scroll_area(self): manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter) manager.counters['dummy'] = 3 term = manager.term stdread = self.tty.stdread self.assertEqual(manager.scroll_offset, 1) self.assertFalse(manager.process_exit) self.assertNotEqual(signal.getsignal(signal.SIGWINCH), manager._resize_handler) with mock.patch('enlighten.atexit') as atexit: with mock.patch.object(term, 'change_scroll'): manager._set_scroll_area() self.assertEqual(term.change_scroll.call_count, 1) # pylint: disable=no-member self.assertEqual(manager.scroll_offset, 4) self.assertEqual(signal.getsignal(signal.SIGWINCH), manager._resize_handler) self.assertEqual(stdread.readline(), term.move(24, 0) + '\n') self.assertEqual(stdread.readline(), '\n') self.assertEqual(stdread.readline(), '\n') self.assertTrue(manager.process_exit) atexit.register.assert_called_with(manager._at_exit) self.tty.stdout.write('X\n') self.assertEqual(stdread.readline(), term.move(21, 0) + 'X\n') # Run it again and make sure exit handling isn't reset with mock.patch('enlighten.atexit') as atexit: with mock.patch.object(term, 'change_scroll'): manager._set_scroll_area(force=True) self.assertEqual(term.change_scroll.call_count, 1) # pylint: disable=no-member self.assertFalse(atexit.register.called)
def fetch(season: int, episode: int, delay: float, all: bool, overwrite: bool, silent_skip: bool): """ Downloads raw quote pages from 'officequotes.net'. Fetches quote pages, placing them in 'html' folder in unmodified UTF-8 HTML files. """ episodes: List[Tuple[int, int]] if all: episodes = list(get_episodes()) elif season: if episode: if verify_episode(season, episode): episodes = [(season, episode)] else: logger.error(f'Season {season}, Episode {episode} is not a valid combination.') return else: episodes = list(get_episodes(season=season)) logger.info(f'Fetching Season {season}...') else: if episode: logger.info('You must specify more than just an episode.') else: logger.info('You must specify which episodes to fetch.') logger.info('Check --help for more information on this command.') return logger.debug(f'Ready to start fetching {len(episodes)} quote page{"s" if len(episodes) > 1 else ""}') session = requests.Session() last_request = time.time() - delay with enlighten.Manager() as manager: with manager.counter(total=len(episodes), desc='Fetching...', unit='episodes') as pbar: for _season, _episode in episodes: filepath = get_filepath(_season, _episode, 'html') # Check if HTML file exists if not overwrite and os.path.exists(filepath): if not silent_skip: logger.debug(f'Skipping Season {_season}, Episode {_episode}: File already exists.') else: logger.info(f'Fetching Season {_season}, Episode {_episode}...') # Generate link, make request link = f"http://officequotes.net/no{_season}-{str(_episode).zfill(2)}.php" sleep_from(delay, last_request, manager) # Sleep at least :delay: seconds. resp = session.get(link) last_request = time.time() if resp.ok: # Write data to file save_file(filepath, resp.text, False) logger.debug('Successfully fetched & saved.') else: logger.error(f'Fetching failed. Erroneous response code {resp.status_code}.') pbar.update() logger.info('Fetching complete.')
def test_resize_handler_height_greater_threaded(self): with mock.patch('%s.height' % TERMINAL, new_callable=mock.PropertyMock) as mockheight: mockheight.side_effect = [25, 27] manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter, threaded=True) counter3 = MockCounter(manager=manager) manager.counters[counter3] = 3 manager.scroll_offset = 4 term = manager.term with mock.patch('enlighten._manager.Manager._set_scroll_area') as ssa: manager._resize_handler() self.assertEqual(ssa.call_count, 1) self.assertEqual(manager.height, 27) self.tty.stdout.write(u'X\n') self.assertEqual(self.tty.stdread.readline(), term.move(27, 0) + '\n') self.assertEqual(self.tty.stdread.readline(), '\n') self.assertEqual(self.tty.stdread.readline(), '\n') self.assertEqual(self.tty.stdread.readline(), term.move(23, 0) + term.clear_eos + 'X\n') self.assertEqual(counter3.calls, ['refresh(flush=False, elapsed=None)'])
def test_stop_companion(self): """ In this case, we have a companion terminal Just make sure we have an extra reset """ manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter, companion_stream=self.tty.stdout) manager.counters[MockCounter(manager=manager)] = 3 manager.counters[MockCounter(manager=manager)] = 4 term = manager.term with mock.patch('enlighten._manager.atexit'): manager._set_scroll_area() del manager._buffer[:] del manager._companion_buffer[:] with mock.patch.object(manager, '_flush_streams'): manager.stop() self.assertEqual(manager._buffer, [term.move(term.height - 2, 0), term.clear_eol, term.move(term.height - 1, 0), term.clear_eol, term.normal_cursor, term.csr(0, term.height - 1), term.move(term.height, 0)]) self.assertEqual(manager._companion_buffer, [term.normal_cursor, term.csr(0, term.height - 1), term.move(term.height, 0)])
def test_stop_position_1(self): """ Ensure a line feed is given if there is a counter at position 1 """ manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter) term = manager.term manager.counters[MockCounter(manager=manager)] = 3 with mock.patch.object(manager, '_flush_streams'): manager.stop() self.assertEqual(manager._buffer, [term.normal_cursor, term.csr(0, term.height - 1), term.move(term.height, 0)]) del manager._buffer[:] manager.enabled = True manager.counters[MockCounter(manager=manager)] = 1 with mock.patch.object(manager, '_flush_streams'): manager.stop() self.assertEqual(manager._buffer, [term.normal_cursor, term.csr(0, term.height - 1), term.move(term.height, 0), term.cud1 or '\n'])
def test_set_scroll_area_no_change(self): manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter) manager.counters['dummy'] = 3 manager.scroll_offset = 4 manager._set_scroll_area() self.assertEqual(manager._buffer, [manager.term.move(21, 0)])
def test_stop_no_set_scroll(self): """ set_scroll is False """ with mock.patch('enlighten.Terminal.reset') as reset: manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter, set_scroll=False) manager.counters[MockCounter(manager=manager)] = 3 manager.counters[MockCounter(manager=manager)] = 4 term = manager.term with mock.patch('enlighten.atexit'): with mock.patch.object(term, 'change_scroll'): manager._set_scroll_area() self.assertEqual(manager.scroll_offset, 5) self.assertEqual(signal.getsignal(signal.SIGWINCH), manager._resize_handler) self.assertTrue(manager.process_exit) # Stream empty self.tty.stdout.write('X\n') self.assertEqual(self.tty.stdread.readline(), 'X\n') manager.stop() self.assertEqual(signal.getsignal(signal.SIGWINCH), manager.sigwinch_orig) self.assertFalse(reset.called) self.tty.stdout.write('X\n') self.assertEqual(self.tty.stdread.readline(), term.move(23, 0) + term.clear_eol + term.move(24, 0) + term.clear_eol + term.move(25, 0) + 'X\n') self.assertFalse(manager.process_exit)
def test_flush_companion_buffer(self): """ Output is stored in buffer, but only written in companion stream is defined """ manager = enlighten.Manager(stream=self.tty.stdout) msg = u'test message' manager._companion_buffer = [msg] manager._flush_streams() # Companion buffer flushed, but not outputted self.assertEqual(manager._companion_buffer, []) self.tty.stdout.write(u'X\n') self.assertEqual(self.tty.stdread.readline(), 'X\n') # set companion stream and test again manager.companion_stream = OUTPUT manager._companion_buffer = [msg] manager._flush_streams() self.assertEqual(manager._companion_buffer, []) self.tty.stdout.write(u'X\n') self.assertEqual(self.tty.stdread.readline(), 'X\n') self.assertEqual(OUTPUT.getvalue(), msg)
def test_counter_replaced(self): """Counter replaces an existing counter""" manager = enlighten.Manager(stream=self.tty.stdout, set_scroll=False) # Pinned replacement counter1 = manager.counter(position=2) self.assertEqual(manager.counters[counter1], 2) counter2 = manager.counter(replace=counter1) self.assertEqual(len(manager.counters), 1) self.assertEqual(manager.counters[counter2], 2) self.assertTrue(counter2._pinned) # Unpinned replacement counter3 = manager.counter() self.assertEqual(len(manager.counters), 2) self.assertEqual(manager.counters[counter3], 1) counter4 = manager.counter(replace=counter3) self.assertEqual(len(manager.counters), 2) self.assertEqual(manager.counters[counter4], 1) self.assertFalse(counter4._pinned) # Unmanaged counter given with self.assertRaisesRegex(ValueError, 'Counter to replace is not currently managed'): manager.counter(replace=counter1)
def test_counter_position_pinned(self): """If a position is taken, use next available""" manager = enlighten.Manager(stream=self.tty.stdout, set_scroll=False) counter1 = manager.counter(position=2) self.assertEqual(manager.counters[counter1], 2) counter2 = manager.counter() self.assertEqual(manager.counters[counter1], 2) self.assertEqual(manager.counters[counter2], 1) counter3 = manager.counter() self.assertEqual(manager.counters[counter1], 2) self.assertEqual(manager.counters[counter2], 3) self.assertEqual(manager.counters[counter3], 1) status1 = manager.status_bar(position=3) self.assertEqual(manager.counters[counter1], 2) self.assertEqual(manager.counters[counter2], 4) self.assertEqual(manager.counters[counter3], 1) self.assertEqual(manager.counters[status1], 3) status2 = manager.status_bar() self.assertEqual(manager.counters[counter1], 2) self.assertEqual(manager.counters[counter2], 5) self.assertEqual(manager.counters[counter3], 4) self.assertEqual(manager.counters[status1], 3) self.assertEqual(manager.counters[status2], 1)
def test_counter_and_remove(self): # pylint: disable=no-member,assigning-non-slot manager = enlighten.Manager(counter_class=MockCounter) self.assertEqual(len(manager.counters), 0) with mock.patch.object(manager, '_set_scroll_area') as ssa: counter1 = manager.counter(leave=True) self.assertTrue(counter1.leave) self.assertEqual(len(manager.counters), 1) self.assertEqual(manager.counters[counter1], 1) self.assertEqual(counter1.calls, []) self.assertEqual(ssa.call_count, 1) with mock.patch.object(manager, '_set_scroll_area') as ssa: counter2 = manager.counter(leave=False) self.assertFalse(counter2.leave) self.assertEqual(len(manager.counters), 2) self.assertEqual(manager.counters[counter1], 2) self.assertEqual(manager.counters[counter2], 1) self.assertEqual(counter1.calls, ['clear(flush=False)', 'refresh(flush=False, elapsed=None)']) self.assertEqual(counter2.calls, []) self.assertEqual(ssa.call_count, 1) counter1.calls = [] with mock.patch.object(manager, '_set_scroll_area') as ssa: counter3 = manager.counter(leave=False) self.assertFalse(counter3.leave) self.assertEqual(len(manager.counters), 3) self.assertEqual(manager.counters[counter1], 3) self.assertEqual(manager.counters[counter2], 2) self.assertEqual(manager.counters[counter3], 1) self.assertEqual(counter1.calls, ['clear(flush=False)', 'refresh(flush=False, elapsed=None)']) self.assertEqual(counter2.calls, ['clear(flush=False)', 'refresh(flush=False, elapsed=None)']) self.assertEqual(counter3.calls, []) self.assertEqual(ssa.call_count, 1) counter1.calls = [] counter2.calls = [] manager.remove(counter3) self.assertEqual(len(manager.counters), 2) self.assertFalse(counter3 in manager.counters) manager.remove(counter1) self.assertEqual(len(manager.counters), 2) self.assertTrue(counter1 in manager.counters) with mock.patch.object(manager, '_set_scroll_area') as ssa: counter4 = manager.counter(leave=False) self.assertFalse(counter4.leave) self.assertEqual(len(manager.counters), 3) self.assertEqual(manager.counters[counter1], 3) self.assertEqual(manager.counters[counter2], 2) self.assertEqual(manager.counters[counter4], 1) self.assertEqual(counter1.calls, []) self.assertEqual(counter2.calls, []) self.assertEqual(counter4.calls, []) self.assertEqual(ssa.call_count, 1)
def test_resize_threaded(self): """ Test a resize event threading behavior """ manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter, threaded=True) counter3 = MockCounter(manager=manager) counter3.last_update = time.time() manager.counters[counter3] = 3 manager.scroll_offset = 4 term = manager.term # simulate resize manager._stage_resize() self.assertTrue(manager._resize) self.assertEqual(counter3.last_update, 0) with mock.patch('%s.width' % TERMINAL, new_callable=mock.PropertyMock) as mockwidth: mockwidth.return_value = 70 # resize doesn't happen until a write is called self.assertEqual(manager.width, 80) with mock.patch('enlighten._manager.Manager._set_scroll_area') as ssa: manager.write() self.assertEqual(ssa.call_count, 1) self.assertEqual(manager.width, 70) self.tty.stdout.write(u'X\n') self.assertEqual(self.tty.stdread.readline(), term.move(21, 0) + term.clear_eos + 'X\n') self.assertFalse(manager.resize_lock) self.assertFalse(manager._resize) self.assertEqual(counter3.calls, ['refresh(flush=False, elapsed=None)'])
def experiment(min_k=10, max_k=1500, input_folder='experiment_2/201103', config_file='../Gnip-Trend-Detection/config_files/config_k.cfg'): print('Step1: generate trends dict and styles') get_trends(input_folder, f'{input_folder}_trends.json') print(f'Step2: generate freq and eta time series from {min_k} to {max_k} k values') manager = enlighten.Manager() counter = manager.counter(total=max_k - min_k) for i in range(min_k,max_k): out_folder = f'{input_folder}/k_values/{i}' if Path(out_folder).exists(): continue flag = process(i, input_folder, out_folder) if not flag: print(f'STOP: {i} Intervals too small') return else: print(f'... generated {i} FTS' ) subprocess.run(['python','../Gnip-Trend-Detection/trend_analyze.py','-c',config_file,'-f', out_folder]) print(f'... generated {i} ETS' ) subprocess.run(['python','../Gnip-Trend-Detection/trend_plot.py','-c',config_file,'-f', out_folder, '-s', f'{input_folder}_trends.json']) print(f'... plotting {i}' ) evaluation(out_folder, f'{input_folder}/k_values/evaluation.csv') print(f'... evaluation {i}' ) counter.update(1)
def main(): coloredlogs.install( level=logging.INFO, fmt="%(asctime)s %(levelname)s %(message)s", datefmt="%H:%M:%S", ) args = get_args() root = args.path.resolve() logging.info("Root: %s", root) logging.info("Discovering files...") files = list(iter_files(root)) logging.info("Discovered %d files.", len(files)) pbar = enlighten.Manager().counter(total=len(files)) errors = pbar.add_subcounter("red") already_in_place = pbar.add_subcounter("green") for path in pbar(files): date = get_date_for_file(path) if not date: logging.error("Failed to parse date from file %s", path.relative_to(root)) errors.update() continue date_subdir = root.joinpath(date.strftime(args.format)) dest = date_subdir.joinpath(path.name) if dest == path: already_in_place.update() continue logging.info("%s -> %s", path.relative_to(root), dest.relative_to(root)) if not args.dry_run: date_subdir.mkdir(parents=True, exist_ok=True) shutil.move(path, dest)
def test_no_resize_signal(self): # Test normal case initialization stdmgr = enlighten.Manager(stream=self.tty.stdout) self.assertTrue(hasattr(stdmgr, 'sigwinch_orig')) stdmgr.counters[MockCounter(manager=stdmgr)] = 3 stdmgr.counters[MockCounter(manager=stdmgr)] = 4 # Test no resize signal initialization with mock.patch.object(enlighten, 'RESIZE_SUPPORTED', False): manager = enlighten.Manager(stream=self.tty.stdout) self.assertFalse(hasattr(manager, 'sigwinch_orig')) manager.counters[MockCounter(manager=manager)] = 3 manager.counters[MockCounter(manager=manager)] = 4 # Test set_scroll_area() with mock.patch.object(enlighten.signal, 'signal', wraps=enlighten.signal.signal) as mocksignal: with mock.patch('enlighten.atexit'): # Test no resize signal set_scroll_area with mock.patch.object(enlighten, 'RESIZE_SUPPORTED', False): with mock.patch.object(manager.term, 'change_scroll'): manager._set_scroll_area() self.assertFalse(mocksignal.called) # Test normal case set_scroll_area with mock.patch.object(stdmgr.term, 'change_scroll'): stdmgr._set_scroll_area() self.assertTrue(mocksignal.called) # Test stop() with mock.patch.object(enlighten.signal, 'signal', wraps=enlighten.signal.signal) as mocksignal: with mock.patch('enlighten.Terminal.reset'): # Test no resize signal stop with mock.patch.object(enlighten, 'RESIZE_SUPPORTED', False): manager.stop() self.assertFalse(mocksignal.called) # Test normal case stop stdmgr.stop() self.assertTrue(mocksignal.called)
def test_set_scroll_area_no_change(self): manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter) manager.counters['dummy'] = 3 manager.scroll_offset = 4 manager._set_scroll_area() self.tty.stdout.write('X\n') self.assertEqual(self.tty.stdread.readline(), manager.term.move(21, 0) + 'X\n')
def test_init_hc(self): # Nonstandard stream doesn't get a companion stream by default manager = enlighten.Manager(stream=OUTPUT) self.assertIs(manager.stream, OUTPUT) self.assertIs(manager.term.stream, OUTPUT) self.assertIsNone(manager.companion_stream) self.assertIsNone(manager.companion_term)
def test_set_scroll_area_disabled(self): manager = enlighten.Manager(stream=self.tty.stdout, counter_class=MockCounter, set_scroll=False) manager.counters['dummy'] = 3 manager._set_scroll_area() self.tty.stdout.write('X\n') self.assertEqual(self.tty.stdread.readline(), 'X\n')
def test_init_stderr(self): # Companion stream is stdout if stream is stderr manager = enlighten.Manager(stream=sys.__stderr__) self.assertIs(manager.stream, sys.__stderr__) self.assertIs(manager.term.stream, sys.__stderr__) # This will fail building rpm packages since stderr is redirected if sys.__stdout__.isatty(): self.assertIs(manager.companion_stream, sys.__stdout__) self.assertIs(manager.companion_term.stream, sys.__stdout__)
def test_init_stderr_redirect(self): # If stderr is redirected, but stdout is still a tty, use it for companion with redirect_output('stderr', OUTPUT): manager = enlighten.Manager(stream=sys.stderr) self.assertIs(manager.stream, sys.stderr) self.assertIs(manager.term.stream, sys.stderr) # This will fail building rpm packages since stderr is redirected if sys.__stdout__.isatty(): self.assertIs(manager.companion_stream, sys.stdout) self.assertIs(manager.companion_term.stream, sys.stdout)
def test_context_manager(self): mgr = None with enlighten.Manager(stream=self.tty.stdout) as manager: self.assertIsInstance(manager, enlighten.Manager) self.assertTrue(manager.enabled) mgr = manager self.assertFalse(mgr.enabled)
def test_counter_position(self): manager = enlighten.Manager(stream=self.tty.stdout, set_scroll=False) counter1 = manager.counter(position=4) self.assertEqual(manager.counters[counter1], 4) with self.assertRaisesRegex(ValueError, 'Counter position 4 is already occupied'): manager.counter(position=4) with self.assertRaisesRegex(ValueError, 'Counter position 200 is greater than terminal height'): manager.counter(position=200)
def test_init(self): # Companion stream is stderr if stream is stdout manager = enlighten.Manager() self.assertIs(manager.stream, sys.__stdout__) self.assertIs(manager.term.stream, sys.__stdout__) # This will fail building rpm packages since stderr is redirected if sys.__stderr__.isatty(): self.assertIs(manager.companion_stream, sys.__stderr__) self.assertIs(manager.companion_term.stream, sys.__stderr__) # Hard-coded companion stream always wins manager = enlighten.Manager(companion_stream=OUTPUT) self.assertIs(manager.companion_stream, OUTPUT) self.assertIs(manager.companion_term.stream, OUTPUT) # Companion stream is stdout if stream is stderr manager = enlighten.Manager(stream=sys.__stderr__) self.assertIs(manager.stream, sys.__stderr__) self.assertIs(manager.term.stream, sys.__stderr__) # This will fail building rpm packages since stderr is redirected if sys.__stdout__.isatty(): self.assertIs(manager.companion_stream, sys.__stdout__) self.assertIs(manager.companion_term.stream, sys.__stdout__) # If stdout is redirected, but stderr is still a tty, use it for companion with redirect_output('stdout', OUTPUT): manager = enlighten.Manager() self.assertIs(manager.stream, sys.stdout) self.assertIs(manager.term.stream, sys.stdout) # This will fail building rpm packages since stderr is redirected if sys.__stderr__.isatty(): self.assertIs(manager.companion_stream, sys.stderr) self.assertIs(manager.companion_term.stream, sys.stderr) # If stderr is redirected, but stdout is still a tty, use it for companion with redirect_output('stderr', OUTPUT): manager = enlighten.Manager(stream=sys.stderr) self.assertIs(manager.stream, sys.stderr) self.assertIs(manager.term.stream, sys.stderr) # This will fail building rpm packages since stderr is redirected if sys.__stdout__.isatty(): self.assertIs(manager.companion_stream, sys.stdout) self.assertIs(manager.companion_term.stream, sys.stdout) # Hard-coded companion stream always wins manager = enlighten.Manager(stream=sys.__stderr__, companion_stream=OUTPUT) self.assertIs(manager.companion_stream, OUTPUT) self.assertIs(manager.companion_term.stream, OUTPUT) # Nonstandard stream doesn't get a companion stream by default manager = enlighten.Manager(stream=OUTPUT) self.assertIs(manager.stream, OUTPUT) self.assertIs(manager.term.stream, OUTPUT) self.assertIsNone(manager.companion_stream) self.assertIsNone(manager.companion_term)
def _get_status_bars_manager(self): config_status_bar = { 'stream': sys.stdout, 'usecounter': True, "set_scroll": True, "resize_lock": True } enablecounter_status_bar = config_status_bar[ 'usecounter'] and config_status_bar['stream'].isatty() return enlighten.Manager(stream=config_status_bar['stream'], enabled=enablecounter_status_bar, set_scroll=config_status_bar['set_scroll'], resize_lock=config_status_bar['resize_lock'])
def test_write(self): msg = 'test message' with mock.patch('enlighten.Manager._set_scroll_area') as ssa: manager = enlighten.Manager(stream=self.tty.stdout) term = manager.term manager.write(msg, position=3) self.tty.stdout.write('X\n') # Carriage return is getting converted to newline self.assertEqual(self.tty.stdread.readline(), term.move(22, 0) + '\r' + term.clear_eol + msg + 'X\n') self.assertEqual(ssa.call_count, 1)
def test_inherit_kwargs(self): manager = enlighten.Manager(counter_class=MockCounter, unit='knights', not_real=True, desc='Default') self.assertTrue('unit' in manager.defaults) self.assertTrue('desc' in manager.defaults) self.assertTrue('not_real' in manager.defaults) with mock.patch.object(manager, '_set_scroll_area'): ctr = manager.counter(desc='Huzzah') self.assertEqual(ctr.unit, 'knights') self.assertEqual(ctr.desc, 'Huzzah') self.assertFalse(hasattr(ctr, 'not_real'))