def test_merge_list_with_scalar(self):
     self.assertEqual({'a': [1, 2, 3]},
                      merge_dicts([{
                          'a': 1
                      }, {
                          'a': [2, 3]
                      }]))
Beispiel #2
0
    def parse_data(cls, title, body, itemtype=u'Article'):
        body = body.replace('\r\n', '\n')

        default_data = {
            'name': title,
            'schema': schema.get_itemtype_path(itemtype)
        }

        # collect
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group('name'), m.group('value'))
                                  for m in re.finditer(cls.re_data, body))

        if itemtype == u'Article' or u'Article' in schema.get_schema(
                itemtype)[u'ancestors']:
            default_section = u'articleBody'
        else:
            default_section = u'longDescription'
        section_data = cls.parse_sections(body, default_section)

        # merge
        data = merge_dicts([default_data, yaml_data, body_data, section_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
 def test_merge_list_with_list(self):
     self.assertEqual({'a': [1, 2, 3, 4]},
                      merge_dicts([{
                          'a': [1, 2]
                      }, {
                          'a': [3, 4]
                      }]))
Beispiel #4
0
    def _parse_outlinks(self):
        # links in hierarchical title and body
        dicts = [
            {
                '%s/relatedTo' % self.itemtype:
                [path[0] for path in self.paths[:-1]]
            },
            md_wikilink.parse_wikilinks(self.itemtype,
                                        WikiPage.remove_metadata(self.body)),
        ]

        # links in structured data
        for name, value in self.data.items():
            if type(value) is list:
                dicts += [self._schema_item_to_links(name, v) for v in value]
            else:
                dicts.append(self._schema_item_to_links(name, value))

        # merge
        merged = merge_dicts(dicts, force_list=True)

        # exclude links to this page
        return dict(
            (k, v) for k, v in merged.items()
            if not ((type(v) == list and self.title in v) or self.title == v))
 def test_sort_values(self):
     self.assertEqual({'a': [1, 2, 3, 4]},
                      merge_dicts([{
                          'a': [1, 3]
                      }, {
                          'a': [2, 4]
                      }],
                                  sort_values=True))
 def test_force_list(self):
     self.assertEqual({
         'a': [1],
         'b': [2],
         'c': [3]
     }, merge_dicts([{
         'a': 1
     }, {
         'b': 2,
         'c': 3
     }], force_list=True))
 def test_merge_two(self):
     self.assertEqual({
         'a': 1,
         'b': 2,
         'c': 3
     }, merge_dicts([{
         'a': 1
     }, {
         'b': 2,
         'c': 3
     }]))
    def parse_data(cls, title, body, itemtype=u'Article'):
        # collect data
        default_data = {'name': title, 'schema': schema.get_itemtype_path(itemtype)}
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group('name'), m.group('value')) for m in re.finditer(cls.re_data, body))
        data = merge_dicts([default_data, yaml_data, body_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
 def test_merge_two_with_conflict_keys(self):
     self.assertEqual({
         'a': 1,
         'b': [2, 3],
         'c': 4
     }, merge_dicts([{
         'a': 1,
         'b': 2
     }, {
         'b': 3,
         'c': 4
     }]))
 def test_duplicated_value(self):
     self.assertEqual({
         'a': [1, 2, 3],
         'b': 4,
         'c': [5, 6]
     },
                      merge_dicts([{
                          'a': [1, 2],
                          'b': 4,
                          'c': [5, 6]
                      }, {
                          'a': [2, 3],
                          'b': 4,
                          'c': 5
                      }]))
Beispiel #11
0
    def _parse_outlinks(self):
        # links in hierarchical title and body
        dicts = [
            {'%s/relatedTo' % self.itemtype: [path[0] for path in self.paths[:-1]]},
            md_wikilink.parse_wikilinks(self.itemtype, WikiPage.remove_metadata(self.body)),
        ]

        # links in structured data
        for name, value in self.data.items():
            if type(value) is list:
                dicts += [self._schema_item_to_links(name, v) for v in value]
            else:
                dicts.append(self._schema_item_to_links(name, value))

        # merge
        merged = merge_dicts(dicts, force_list=True)

        # exclude links to this page
        return dict((k, v) for k, v in merged.items()
                    if not((type(v) == list and self.title in v) or self.title == v))
Beispiel #12
0
    def parse_data(cls, title, body, itemtype=u"Article"):
        body = body.replace("\r\n", "\n")

        default_data = {"name": title, "schema": schema.get_itemtype_path(itemtype)}

        # collect
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group("name"), m.group("value")) for m in re.finditer(cls.re_data, body))

        if itemtype == u"Article" or u"Article" in schema.get_schema(itemtype)[u"ancestors"]:
            default_section = u"articleBody"
        else:
            default_section = u"longDescription"
        section_data = cls.parse_sections(body, default_section)

        # merge
        data = merge_dicts([default_data, yaml_data, body_data, section_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
Beispiel #13
0
    def parse_data(cls, title, body, itemtype=u'Article'):
        body = body.replace('\r\n', '\n')

        default_data = {'name': title, 'schema': schema.get_itemtype_path(itemtype)}

        # collect
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group('name'), m.group('value')) for m in re.finditer(cls.re_data, body))

        if itemtype == u'Article' or u'Article' in schema.get_schema(itemtype)[u'ancestors']:
            default_section = u'articleBody'
        else:
            default_section = u'longDescription'
        section_data = cls.parse_sections(body, default_section)

        # merge
        data = merge_dicts([default_data, yaml_data, body_data, section_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
Beispiel #14
0
 def test_single_dict(self):
     self.assertEqual({'a': 1}, merge_dicts([{'a': 1}]))
 def test_single_dict(self):
     self.assertEqual({'a': 1}, merge_dicts([{'a': 1}]))
Beispiel #16
0
 def test_force_list(self):
     self.assertEqual({'a': [1], 'b': [2], 'c': [3]},
                      merge_dicts([{'a': 1}, {'b': 2, 'c': 3}], force_list=True))
Beispiel #17
0
 def test_empty(self):
     self.assertEqual({}, merge_dicts([]))
Beispiel #18
0
 def test_duplicated_value(self):
     self.assertEqual({'a': [1, 2, 3], 'b': 4, 'c': [5, 6]},
                      merge_dicts([{'a': [1, 2], 'b': 4, 'c': [5, 6]}, {'a': [2, 3], 'b': 4, 'c': 5}]))
Beispiel #19
0
 def test_sort_values(self):
     self.assertEqual({'a': [1, 2, 3, 4]},
                      merge_dicts([{'a': [1, 3]}, {'a': [2, 4]}], sort_values=True))
Beispiel #20
0
 def test_merge_list_with_list(self):
     self.assertEqual({'a': [1, 2, 3, 4]},
                      merge_dicts([{'a': [1, 2]}, {'a': [3, 4]}]))
Beispiel #21
0
 def test_merge_list_with_scalar(self):
     self.assertEqual({'a': [1, 2, 3]},
                      merge_dicts([{'a': 1}, {'a': [2, 3]}]))
Beispiel #22
0
 def test_merge_two_with_conflict_keys(self):
     self.assertEqual({'a': 1, 'b': [2, 3], 'c': 4},
                      merge_dicts([{'a': 1, 'b': 2}, {'b': 3, 'c': 4}]))
 def test_empty_value(self):
     self.assertEqual({}, merge_dicts([{'a': []}]))
Beispiel #24
0
 def test_empty_value(self):
     self.assertEqual({}, merge_dicts([{'a': []}]))
Beispiel #25
0
 def test_merge_two(self):
     self.assertEqual({'a': 1, 'b': 2, 'c': 3},
                      merge_dicts([{'a': 1}, {'b': 2, 'c': 3}]))
 def test_empty(self):
     self.assertEqual({}, merge_dicts([]))