Exemplo n.º 1
0
 def test_get_arg_parser(self):
     # we can get a populated argparse.ArgumentParser instance
     opts = Options()
     parser = opts.get_arg_parser()
     assert isinstance(parser, argparse.ArgumentParser)
     assert isinstance(parser, ExceptionalArgumentParser)
     # the parser is populated with arguments
     assert '-meta-procord' in parser.format_help()
Exemplo n.º 2
0
 def __init__(self, options=None):
     if options is None:
         options = Options()
     if not isinstance(options, Options):
         options = Options(string_dict=options)
     self.options = options
     self.metadata = {}
     return
Exemplo n.º 3
0
 def test_get_arg_parser(self):
     # we can get a populated argparse.ArgumentParser instance
     opts = Options()
     parser = opts.get_arg_parser()
     assert isinstance(parser, argparse.ArgumentParser)
     assert isinstance(parser, ExceptionalArgumentParser)
     # the parser is populated with arguments
     assert '-meta-procord' in parser.format_help()
Exemplo n.º 4
0
 def test_get_arg_parser_custom(self):
     # we can pass in an own parser that will be populated
     opts = Options()
     in_parser = argparse.ArgumentParser()
     out_parser = opts.get_arg_parser(parser=in_parser)
     assert isinstance(out_parser, argparse.ArgumentParser)
     assert not isinstance(out_parser, ExceptionalArgumentParser)
     assert out_parser is in_parser
     # the parser is populated with arguments
     assert '-meta-procord' in out_parser.format_help()
Exemplo n.º 5
0
 def test_get_arg_parser_custom(self):
     # we can pass in an own parser that will be populated
     opts = Options()
     in_parser = argparse.ArgumentParser()
     out_parser = opts.get_arg_parser(parser=in_parser)
     assert isinstance(out_parser, argparse.ArgumentParser)
     assert not isinstance(out_parser, ExceptionalArgumentParser)
     assert out_parser is in_parser
     # the parser is populated with arguments
     assert '-meta-procord' in out_parser.format_help()
Exemplo n.º 6
0
 def test_failing_op(self):
     proc = OOConvProcessor(Options())
     sample_file = os.path.join(self.workdir, 'sample.txt')
     with open(sample_file, 'w') as fd:
         fd.write('A sample')
     with self.failing_unoconv_context():
         # the fake unoconv will return error unconditionally
         self.result_path, meta = proc.process(sample_file, Options())
     assert meta['oocp_status'] == 1
     assert self.result_path is None
     return
Exemplo n.º 7
0
 def test_string_dict(self):
     # we can feed Options with a dict of keys/string-values
     opts = Options(string_dict={'oocp-pdf-version': 'yes'})
     # default options are set
     assert opts['meta_processor_order'] == DEFAULT_PROCORDER
     # default options can be overridden
     assert opts['oocp_pdf_version'] is True
Exemplo n.º 8
0
 def __init__(self, options={}):
     from ulif.openoffice.options import Options
     if not isinstance(options, Options):
         options = Options(string_dict=options)
     self.all_options = options
     self.options = options
     self.metadata = {}
     return
Exemplo n.º 9
0
 def test_val_dict(self):
     # we can feed Options with a dict of keys/values
     opts = Options(val_dict=dict(x=1, oocp_output_format='pdf'))
     # default options are set
     assert opts['meta_processor_order'] == DEFAULT_PROCORDER
     # default options can be overridden
     assert opts['oocp_output_format'] == 'pdf'
     # non-processor opts can be set
     assert opts['x'] == 1
Exemplo n.º 10
0
 def test_string_keys(self):
     # we can get a list of acceptable string options
     opts = Options()
     assert opts.string_keys == [
         'css-cleaner-min', 'css-cleaner-prettify',
         'html-cleaner-fix-head-nums', 'html-cleaner-fix-img-links',
         'html-cleaner-fix-sd-fields', 'meta-procord', 'oocp-host',
         'oocp-out-fmt', 'oocp-pdf-tagged', 'oocp-pdf-version', 'oocp-port'
     ]
Exemplo n.º 11
0
def main(args=None):
    parser = argparse.ArgumentParser()
    if args is None:                                    # pragma: no cover
        args = sys.argv[1:]
    else:
        parser.prog = 'oooclient'
    parser.add_argument('src', metavar='SOURCEFILE',
                        help='The office document to be converted')
    parser.add_argument('--cachedir',
                        help='Path to a cache directory')
    parser.description = "A tool to convert office documents."
    parser = Options().get_arg_parser(parser)
    options = vars(parser.parse_args(args))
    cache_dir = options['cachedir']
    src = options['src']
    options = Options(val_dict=options)
    result_path, cache_key, metadata = convert_doc(
        src, options, cache_dir=cache_dir)
    print("RESULT in " + result_path)
Exemplo n.º 12
0
def main(args=None):
    parser = argparse.ArgumentParser()
    if args is None:  # pragma: no cover
        args = sys.argv[1:]
    else:
        parser.prog = 'oooclient'
    parser.add_argument('src',
                        metavar='SOURCEFILE',
                        help='The office document to be converted')
    parser.add_argument('--cachedir', help='Path to a cache directory')
    parser.description = "A tool to convert office documents."
    parser = Options().get_arg_parser(parser)
    options = vars(parser.parse_args(args))
    cache_dir = options['cachedir']
    src = options['src']
    options = Options(val_dict=options)
    result_path, cache_key, metadata = convert_doc(src,
                                                   options,
                                                   cache_dir=cache_dir)
    print("RESULT in " + result_path)
Exemplo n.º 13
0
 def test_avail_procs(self):
     # Options provide a list of available processor opts
     opts = Options()
     avail_procs = opts.avail_procs
     core_procs = [
         'css_cleaner',
         'error',
         'html_cleaner',
         'meta',
         'oocp',
         'tidy',
         'unzip',
         'zip',
     ]
     for name in core_procs:
         assert name in avail_procs
Exemplo n.º 14
0
 def test_no_options(self):
     opts = Options()
     # default values are set
     assert opts['meta_processor_order'] == DEFAULT_PROCORDER
     assert opts['oocp_output_format'] == 'html'
Exemplo n.º 15
0
 def test_val_dict_overrides_string_dict(self):
     # val_dict values will override string_dict values
     opts = Options(string_dict={'oocp-out-fmt': 'txt'},
                    val_dict={'oocp_output_format': 'pdf'})
     assert opts['oocp_output_format'] == 'pdf'