コード例 #1
0
ファイル: test_flatten.py プロジェクト: chenl/schematics
    def test_expand_with_both_empty_list_and_values(self):
        different_orderings = [
            [
                ("categories", '[]'),
                ("categories.0", 'basketball'),
                ("categories.1", '0'),
                ("categories.2", '2'),
            ],
            [
                ("categories.0", 'basketball'),
                ("categories", '[]'),
                ("categories.1", '0'),
                ("categories.2", '2'),
            ],
            [
                ("categories.0", 'basketball'),
                ("categories.1", '0'),
                ("categories.2", '2'),
                ("categories", '[]'),
            ]
        ]
        for ordering in different_orderings:
            flat_data = OrderedDict(ordering)

            expanded = expand(flat_data)
            self.assertEqual(expanded, {
                "categories": {
                    "0": "basketball",
                    "1": "0",
                    "2": "2"
                }
            })
コード例 #2
0
    def test_expand_with_both_empty_list_and_values(self):
        different_orderings = [[
            ("categories", '[]'),
            ("categories.0", 'basketball'),
            ("categories.1", '0'),
            ("categories.2", '2'),
        ],
                               [
                                   ("categories.0", 'basketball'),
                                   ("categories", '[]'),
                                   ("categories.1", '0'),
                                   ("categories.2", '2'),
                               ],
                               [
                                   ("categories.0", 'basketball'),
                                   ("categories.1", '0'),
                                   ("categories.2", '2'),
                                   ("categories", '[]'),
                               ]]
        for ordering in different_orderings:
            flat_data = OrderedDict(ordering)

            expanded = expand(flat_data)
            self.assertEqual(
                expanded,
                {"categories": {
                    "0": "basketball",
                    "1": "0",
                    "2": "2"
                }})
コード例 #3
0
ファイル: test_flatten.py プロジェクト: chenl/schematics
    def test_expand_with_both_empty_dict_and_values(self):
        different_orderings = [
            [
                ("categories", '{}'),
                ("categories.basketball.category_slug", 'basketball'),
                ("categories.basketball.total_draws", '0'),
                ("categories.basketball.total_losses", '2'),
            ],
            [
                ("categories.basketball.category_slug", 'basketball'),
                ("categories", '{}'),
                ("categories.basketball.total_draws", '0'),
                ("categories.basketball.total_losses", '2'),
            ],
            [
                ("categories.basketball.category_slug", 'basketball'),
                ("categories.basketball.total_draws", '0'),
                ("categories.basketball.total_losses", '2'),
                ("categories", '{}'),
            ]
        ]

        for ordering in different_orderings:
            flat_data = OrderedDict(ordering)

            expanded = expand(flat_data)
            self.assertEqual(expanded, {
                "categories": {
                    "basketball": {
                        "category_slug": "basketball",
                        "total_draws": "0",
                        "total_losses": "2",
                    }
                }
            })
コード例 #4
0
    def test_expand_with_both_empty_dict_and_values(self):
        different_orderings = [[
            ("categories", '{}'),
            ("categories.basketball.category_slug", 'basketball'),
            ("categories.basketball.total_draws", '0'),
            ("categories.basketball.total_losses", '2'),
        ],
                               [
                                   ("categories.basketball.category_slug",
                                    'basketball'),
                                   ("categories", '{}'),
                                   ("categories.basketball.total_draws", '0'),
                                   ("categories.basketball.total_losses", '2'),
                               ],
                               [
                                   ("categories.basketball.category_slug",
                                    'basketball'),
                                   ("categories.basketball.total_draws", '0'),
                                   ("categories.basketball.total_losses", '2'),
                                   ("categories", '{}'),
                               ]]

        for ordering in different_orderings:
            flat_data = OrderedDict(ordering)

            expanded = expand(flat_data)
            self.assertEqual(
                expanded, {
                    "categories": {
                        "basketball": {
                            "category_slug": "basketball",
                            "total_draws": "0",
                            "total_losses": "2",
                        }
                    }
                })