Пример #1
0
 def test_unicode_coercion(self):
     object_ = object()
     content = ['p', object_]
     self.assertEqual(
         render(content),
         '<p>{}</p>'.format(str(object_))
     )
Пример #2
0
 def test_class_names_are_extended_via_iterable_attribute(self):
     classes = (_ for _ in ['bar', 'baz'])
     content = ['span.foo', {'class': classes}, 'hello']
     self.assertEqual(
         render(content),
         u'<span class="foo bar baz">hello</span>'
     )
Пример #3
0
 def test_unicode_coercion(self):
     object_ = object()
     content = ['p', object_]
     self.assertEqual(
         render(content),
         u'<p>{}</p>'.format(unicode(object_))
     )
Пример #4
0
    def test_readme_example(self):
        from cottonmouth.tags import html, head, body, title, meta, link, h1

        def welcome(user=None, **context):
            return ['p', 'Welcome' + (' back!' if user else '!')]

        content = ('<!doctype html>', [
            html,
            [
                head, [title, 'The Site'],
                [
                    meta, {
                        'http-equiv': 'content-type',
                        'content': 'text/html;charset=utf-8'
                    }
                ],
                [
                    link,
                    dict(rel='stylesheet',
                         type='text/css',
                         href='static/layout.css')
                ]
            ],
            [
                body,
                h1(u'Welcome to the site!', id='header'), ['#map.pretty-map'],
                ['#main', welcome]
            ]
        ])
        self.assertTrue(isinstance(render(*content), unicode))
Пример #5
0
 def test_class_names_are_extended_via_iterable_attribute(self):
     classes = (_ for _ in ['bar', 'baz'])
     content = ['span.foo', {'class': classes}, 'hello']
     self.assertEqual(
         render(content),
         '<span class="foo bar baz">hello</span>'
     )
Пример #6
0
 def test_generator(self):
     self.assertEqual(
         render(['#container',
                 ['ul', (['li', l] for l in 'ABCDXYZ' if l < 'X')]]),
         ('<div id="container">'
          '<ul><li>A</li><li>B</li><li>C</li><li>D</li></ul>'
          '</div>')
     )
Пример #7
0
 def test_generator(self):
     self.assertEqual(
         render([
             '#container',
             ['ul', (['li', l] for l in 'ABCDXYZ' if l < 'X')]
         ]), ('<div id="container">'
              '<ul><li>A</li><li>B</li><li>C</li><li>D</li></ul>'
              '</div>'))
Пример #8
0
 def test_embedded_content_with_conditional_list_item(self):
     image = ['img', {'src': 'embedded.jpg'}]
     self.assertEqual(
         render([
             '#container', {
                 'data-attr': '123'
             }, image, ['hr'],
             [
                 'ul', ['li', 'A'], ['li', 'B'], ['li', 'C'], ['li', 'D'],
                 ['li', 'Z'] if False else None
             ]
         ]), ('<div data-attr="123" id="container">'
              '<img src="embedded.jpg"><hr>'
              '<ul><li>A</li><li>B</li><li>C</li><li>D</li></ul>'
              '</div>'))
Пример #9
0
 def test_embedded_content_with_conditional_list_item(self):
     image = ['img', {'src': 'embedded.jpg'}]
     self.assertEqual(
         render(['#container', {'data-attr': '123'},
                 image, ['hr'],
                 ['ul',
                     ['li', 'A'],
                     ['li', 'B'],
                     ['li', 'C'],
                     ['li', 'D'],
                     ['li', 'Z'] if False else None]]),
         ('<div data-attr="123" id="container">'
          '<img src="embedded.jpg"><hr>'
          '<ul><li>A</li><li>B</li><li>C</li><li>D</li></ul>'
          '</div>')
     )
Пример #10
0
    def test_readme_example(self):
        from cottonmouth.tags import html, head, body, title, meta, link, h1

        def welcome(user=None, **context):
            return ['p', 'Welcome' + (' back!' if user else '!')]

        content = (
            '<!doctype html>',
            [html,
                [head,
                    [title, 'The Site'],
                    [meta, {'http-equiv': 'content-type',
                            'content': 'text/html;charset=utf-8'}],
                    [link, dict(rel='stylesheet', type='text/css',
                                href='static/layout.css')]],
                [body,
                    h1(u'Welcome to the site!', id='header'),
                    ['#map.pretty-map'],
                    ['#main', welcome]]]
        )
        self.assertTrue(isinstance(render(*content), unicode))
Пример #11
0
 def test_image(self):
     self.assertEqual(render(['img', {
         'src': 'image.png'
     }]), '<img src="image.png">')
Пример #12
0
 def test_class_names_are_extended_via_list_attribute(self):
     content = ['span.foo', {'class': ['bar', 'baz']}, 'hello']
     self.assertEqual(render(content),
                      u'<span class="foo bar baz">hello</span>')
Пример #13
0
 def test_div_shortcut_with_classname(self):
     self.assertEqual(render(['.test', 'testing']),
                      '<div class="test">testing</div>')
Пример #14
0
 def test_image(self):
     self.assertEqual(
         render(['img', {'src': 'image.png'}]),
         '<img src="image.png">'
     )
Пример #15
0
 def test_div_shortcut_with_content(self):
     self.assertEqual(render(['#my.test', 'testing']),
                      '<div id="my" class="test">testing</div>')
Пример #16
0
 def test_callable(self):
     say_hello = lambda name: ['p', 'Hello, {}!'.format(name)]
     self.assertEqual(render(['#container', say_hello], name='USER'),
                      '<div id="container"><p>Hello, USER!</p></div>')
Пример #17
0
 def test_input_tag_checked(self):
     content = ['input', {'type': 'checkbox', 'checked': True}]
     self.assertEqual(
         render(content),
         '<input type="checkbox" checked="true"></input>'
     )
Пример #18
0
 def test_p_with_content(self):
     self.assertEqual(render(['p', 'paragraph']), '<p>paragraph</p>')
Пример #19
0
 def test_class_names_are_extended_via_string_attribute(self):
     content = ['span.foo', {'class': 'bar'}, 'hello']
     self.assertEqual(
         render(content),
         u'<span class="foo bar">hello</span>'
     )
Пример #20
0
 def test_p_tag(self):
     self.assertEqual(next(tags.p('paragraph 1')), ['p', {}, 'paragraph 1'])
     self.assertEqual(
         render(['#container', tags.p('paragraph 2')]),
         '<div id="container"><p>paragraph 2</p></div>'
     )
Пример #21
0
 def test_input_tag_closed(self):
     content = ['input', {'type': 'text'}, 'hello']
     self.assertEqual(
         render(content),
         '<input type="text">hello</input>'
     )
Пример #22
0
 def test_callable(self):
     say_hello = lambda name: ['p', 'Hello, {}!'.format(name)]
     self.assertEqual(
         render(['#container', say_hello], name='USER'),
         '<div id="container"><p>Hello, USER!</p></div>'
     )
Пример #23
0
 def test_class_names_are_extended_via_list_attribute(self):
     content = ['span.foo', {'class': ['bar', 'baz']}, 'hello']
     self.assertEqual(
         render(content),
         u'<span class="foo bar baz">hello</span>'
     )
Пример #24
0
 def test_div_shortcut_with_classname(self):
     self.assertEqual(
         render(['.test', 'testing']),
         '<div class="test">testing</div>'
     )
Пример #25
0
 def test_class_name_are_set_via_attributes(self):
     content = ['span', {'class': 'foo'}, 'hello']
     self.assertEqual(
         render(content),
         u'<span class="foo">hello</span>'
     )
Пример #26
0
def main():
    args = get_args()
    datasets, clonal_families_dict, reconstructions = [], {}, []

    for infile in args.inputs or []:
        print "\nProcessing infile:", str(infile)
        try:
            with open(infile, 'r') as fh:
                dataset = json.load(fh)
                if dataset_schema.is_valid(dataset):
                    dataset = process_dataset(dataset)
                    clonal_families = map(
                        fun.partial(process_clonal_family, args, dataset),
                        dataset['clonal_families'])
                    reconstructions += reduce(
                        lambda recons, cf: recons + cf['reconstructions'],
                        clonal_families, [])
                    for cf in clonal_families:
                        cf['reconstructions'] = [
                            dict_subset(recon, [
                                'prune_strategy', 'ident', 'type', 'id',
                                'prune_count'
                            ]) for recon in cf['reconstructions']
                        ]
                    clonal_families_dict[dataset['id']] = clonal_families
                    del dataset['clonal_families']
                    datasets.append(dataset)
                else:
                    message = "Dataset doesn't conform to spec." + "" if args.verbose else " Please rerunn with `-v` for detailed errors"
                    print(message)
                    if args.verbose:
                        last_error_path = None
                        for error in dataset_schema.iter_errors(dataset):
                            error_path = list(error.path)
                            if last_error_path != error_path:
                                print("  Error at " + str(error_path) + ":")
                                last_error_path = error_path
                            print("    " + error.message)
                            # import pdb; pdb.set_trace()
        except Exception as e:
            message = "Unable to process infile: " + str(
                infile
            ) + "" if args.verbose else " Please rerunn with `-v` for detailed errors"
            print(message)
            if args.verbose:
                exc_info = sys.exc_info()
                traceback.print_exception(*exc_info)

    if args.display_schema:
        pprint.pprint(dataset_spec)
    if args.display_schema_html:
        with open(args.display_schema_html, 'w') as fh:
            fh.write(
                hiccup.render([
                    "html",
                    [
                        "body",
                        hiccup_rep2(dataset_spec),
                        # hiccup_rep(dataset_spec)
                    ]
                ]))
    # write out data
    if args.data_outdir:
        write_out(datasets, args.data_outdir, 'datasets.json', args)
        for dataset_id, clonal_families in clonal_families_dict.items():
            write_out(clonal_families, args.data_outdir + '/',
                      'clonal_families.' + dataset_id + '.json', args)
        for reconstruction in reconstructions:
            write_out(reconstruction, args.data_outdir + '/',
                      'reconstruction.' + reconstruction['ident'] + '.json',
                      args)
Пример #27
0
 def test_attribute_dicts_as_style_tags(self):
     content = ['div', {'style': {'visibility': 'hidden'}}]
     self.assertEqual(
         render(content),
         '<div style="visibility: hidden;"></div>'
     )
Пример #28
0
 def test_class_name_are_set_via_attributes(self):
     content = ['span', {'class': 'foo'}, 'hello']
     self.assertEqual(render(content), u'<span class="foo">hello</span>')
Пример #29
0
 def test_p_tag(self):
     self.assertEqual(next(tags.p('paragraph 1')), ['p', {}, 'paragraph 1'])
     self.assertEqual(render(['#container',
                              tags.p('paragraph 2')]),
                      '<div id="container"><p>paragraph 2</p></div>')
Пример #30
0
 def test_class_names_are_extended_via_string_attribute(self):
     content = ['span.foo', {'class': 'bar'}, 'hello']
     self.assertEqual(render(content),
                      u'<span class="foo bar">hello</span>')
Пример #31
0
 def test_p_with_content(self):
     self.assertEqual(render(['p', 'paragraph']), '<p>paragraph</p>')
Пример #32
0
 def test_div_shortcut_with_content(self):
     self.assertEqual(
         render(['#my.test', 'testing']),
         '<div id="my" class="test">testing</div>'
     )