Пример #1
0
    def migrate_context(cls, context, version):
        if version < 2:
            settings.migrate_str_to_variable(context,
                                             names="lat_attr",
                                             none_placeholder="")
            settings.migrate_str_to_variable(context,
                                             names="lon_attr",
                                             none_placeholder="")
            settings.migrate_str_to_variable(context,
                                             names="class_attr",
                                             none_placeholder="(None)")

            # those settings can have two none placeholder
            attr_placeholders = [("color_attr", "(Same color)"),
                                 ("label_attr", "(No labels)"),
                                 ("shape_attr", "(Same shape)"),
                                 ("size_attr", "(Same size)")]
            for attr, place in attr_placeholders:
                if context.values[attr][0] == place:
                    context.values[attr] = ("", context.values[attr][1])

                settings.migrate_str_to_variable(context,
                                                 names=attr,
                                                 none_placeholder="")
        if version < 3:
            settings.rename_setting(context, "lat_attr", "attr_lat")
            settings.rename_setting(context, "lon_attr", "attr_lon")
            settings.rename_setting(context, "color_attr", "attr_color")
            settings.rename_setting(context, "label_attr", "attr_label")
            settings.rename_setting(context, "shape_attr", "attr_shape")
            settings.rename_setting(context, "size_attr", "attr_size")
Пример #2
0
    def migrate_context(cls, context, version):
        if version < 2:
            migrate_str_to_variable(context,
                                    names="lat_attr",
                                    none_placeholder="")
            migrate_str_to_variable(context,
                                    names="lon_attr",
                                    none_placeholder="")
            migrate_str_to_variable(context, names="attr", none_placeholder="")

            rename_setting(context, "lat_attr", "attr_lat")
            rename_setting(context, "lon_attr", "attr_lon")
            rename_setting(context, "attr", "agg_attr")
            # old selection will not be ported
            rename_setting(context, "selection", "old_selection")

            if context.values["agg_func"][0] == "Max":
                context.values["agg_func"] = ("Maximal",
                                              context.values["agg_func"][1])
            elif context.values["agg_func"][0] == "Min":
                context.values["agg_func"] = ("Minimal",
                                              context.values["agg_func"][1])
            elif context.values["agg_func"][0] == "Std":
                context.values["agg_func"] = ("Std.",
                                              context.values["agg_func"][1])
Пример #3
0
    def test_migrate_str_to_variable(self):
        values = dict(foo=("foo", 1), baz=("baz", 2), qux=("qux", 102), bar=13)

        context = Context(values=values.copy())
        migrate_str_to_variable(context)
        self.assertDictEqual(
            context.values,
            dict(foo=("foo", 101), baz=("baz", 102), qux=("qux", 102), bar=13),
        )

        context = Context(values=values.copy())
        migrate_str_to_variable(context, ("foo", "qux"))
        self.assertDictEqual(
            context.values,
            dict(foo=("foo", 101), baz=("baz", 2), qux=("qux", 102), bar=13),
        )

        context = Context(values=values.copy())
        migrate_str_to_variable(context, "foo")
        self.assertDictEqual(
            context.values,
            dict(foo=("foo", 101), baz=("baz", 2), qux=("qux", 102), bar=13),
        )

        self.assertRaises(KeyError, migrate_str_to_variable, context, "quuux")
Пример #4
0
    def test_migrate_str_to_variable(self):
        values = dict(foo=("foo", 1), baz=("baz", 2), qux=("qux", 102), bar=13)

        context = Context(values=values.copy())
        migrate_str_to_variable(context)
        self.assertDictEqual(
            context.values,
            dict(foo=("foo", 101), baz=("baz", 102), qux=("qux", 102), bar=13))

        context = Context(values=values.copy())
        migrate_str_to_variable(context, ("foo", "qux"))
        self.assertDictEqual(
            context.values,
            dict(foo=("foo", 101), baz=("baz", 2), qux=("qux", 102), bar=13))

        context = Context(values=values.copy())
        migrate_str_to_variable(context, "foo")
        self.assertDictEqual(
            context.values,
            dict(foo=("foo", 101), baz=("baz", 2), qux=("qux", 102), bar=13))

        self.assertRaises(KeyError, migrate_str_to_variable, context, "quuux")
Пример #5
0
 def migrate_context(cls, context, version):
     if version < 2:
         settings.migrate_str_to_variable(context,
                                          none_placeholder="(None)")
Пример #6
0
 def migrate_context(cls, context, version):
     if not version:
         settings.rename_setting(context, "attrX", "attr_x")
         settings.rename_setting(context, "attrY", "attr_y")
         settings.migrate_str_to_variable(context)
Пример #7
0
 def migrate_context(cls, context, version):
     if version < 2:
         for attr in ["str_attr", "lat_attr", "lon_attr"]:
             settings.migrate_str_to_variable(context,
                                              names=attr,
                                              none_placeholder="")
Пример #8
0
 def migrate_context(cls, context, version):
     if not version:
         settings.rename_setting(context, "attrX", "attr_x")
         settings.rename_setting(context, "attrY", "attr_y")
         settings.migrate_str_to_variable(context)
Пример #9
0
 def migrate_context(cls, context, version):
     if version < 2:
         settings.migrate_str_to_variable(context, none_placeholder="(None)")