Example #1
0
 def test_exception(self):
     try:
         1 + ''
     except Exception as e:
         console.error('oh no!', e)
         out, err = self.finish(truncate=40)
         self.assertEqual(err, ['ERROR: oh no!', 'ERROR: Exception[TypeError]: unsupported'])
Example #2
0
def choose_archive(name, program_name, output_directory, **item_kwargs):
    """Prompt for choosing an archive."""
    if not os.path.isdir(output_directory):
        console.abort('No %s directory exists' % output_directory)
    if name[-1] == '/':
        name = name[:-1]
    pat = os.path.join(output_directory, ARCHIVE_NAME_GLOB % name)
    archives = []
    for ls_stream in os.popen('ls %s' % pat):
        archives.insert(0, ls_stream.strip())
    if not archives:
        console.abort('No archives found')
    console.info('Newest archive is at the top.  Empty input or zero response cancels the action.')
    for index, archive in range(len(archives)):
        console.info('%d) %s' % (index + 1, archive))
    console.info('')
    path = None
    while path is None:
        archive_index = int(
            console.prompt_re('Select archive (1-n [none])',
                              NUMBER_WITH_DEFAULT_RE,
                              '0')
        )
        if archive_index <= 0:
            console.abort('Canceled')
        if archive_index-1 < len(archives):
            path = archives[archive_index-1]
        else:
            console.error('bad index %d' % archive_index)
    return item_for_path(path, program_name, **item_kwargs)
Example #3
0
 def test_simple(self):
     console.info('info')
     console.verbose_info('verbose-')
     self.set_verbose(True)
     console.verbose_info('verbose+')
     console.debug('debug-')
     self.set_debug(True)
     console.debug('debug+')
     console.warning('warning')
     console.error('error')
     out, err = self.finish()
     self.assertEqual(out, ['info', 'INFO2: verbose+'])
     self.assertEqual(err, ['DEBUG: debug+', 'WARNING: warning', 'ERROR: error'])