Beispiel #1
0
    def do_settings_reset(self, args):
        """
        Display or change CliMetLab settings.
        See https://climetlab.readthedocs.io/guide/settings.html for more details.

        Examples: climetlab settings cache-directory /big-disk/climetlab-cache
        """
        from climetlab import settings

        words = args.args

        if len(words) == 0:
            if args.all:
                settings.reset()
                return

            print(
                colored(
                    "To reset all settings, please use the --all flag. Use --help for more information.",
                    "red",
                ))
            return

        if len(words) == 1:
            name = words[0]
            settings.reset(name)
            return

        print(colored(
            f"Too many settings to reset ({words}).",
            "red",
        ))
Beispiel #2
0
def test_settings():

    settings.reset()

    assert settings.get("plotting-options") == {}, "Check 1"
    settings.set("plotting-options", width=400)
    assert settings.get("plotting-options") == {"width": 400}
    settings.reset("plotting-options")
    assert settings.get("plotting-options") == {}, "Check 2"
    settings.set("plotting-options", {"width": 400})
    assert settings.get("plotting-options") == {"width": 400}
    settings.reset()
    assert settings.get("plotting-options") == {}, "Check 3"

    with pytest.raises(TypeError):
        settings.set("plotting-options", 3)

    settings.set("styles-directories", ["/a", "/b"])
    assert settings.get("styles-directories") == ["/a", "/b"]

    settings.set("styles-directories", "/c", "/d")
    assert settings.get("styles-directories") == ["/c", "/d"]

    with pytest.raises(KeyError):
        settings.set("test", 42)

    with pytest.raises(KeyError):
        settings.get("test")

    settings.reset()
Beispiel #3
0
def test_temporary():

    settings.reset()

    settings.set("styles-directories", "/c", "/d")
    settings.set("plotting-options", {"width": 400})

    with settings.temporary("plotting-options", {"width": 100}):

        assert settings.get("styles-directories") == ["/c", "/d"]
        assert settings.get("plotting-options") == {"width": 100}, settings.get(
            "plotting-options"
        )
        settings.set("plotting-options", {"width": 200})
        assert settings.get("plotting-options") == {"width": 200}
        settings.reset()
        assert settings.get("plotting-options") == {}

    settings.set("plotting-options", {"width": 400})
    settings.set("styles-directories", "/c", "/d")

    settings.reset()
    assert settings.get("plotting-options") == {}