Пример #1
0
    def test_from_config_no_file(self, config_backup):
        if Path(Options.config_path).exists():
            remove(Options.config_path)

        new_opt = Options.from_config()

        for k, v in DEFAULT_OPTIONS.__dict__.items():
            if hasattr(new_opt, k) and not k.startswith("_"):
                assert getattr(new_opt, k) == v
Пример #2
0
    def test_write_new_section(self, options: Options, config_backup):
        options.timeout = 42
        options.write("https://foo.bar")

        new_opt = Options.from_config("https://foo.bar")
        assert options is not new_opt
        for k, v in options.__dict__.items():
            if k == "url":
                assert v == options.url
                assert new_opt.url == "https://foo.bar"
            elif k == "cache":
                assert type(new_opt.cache) == type(options.cache)  # noqa: E721
            else:
                assert getattr(new_opt, k) == v
Пример #3
0
    def test_write_config(self, options: Options, config_backup):
        options.timeout = 1337
        options.license = License.COMMERCIAL
        options.password = "******"
        options.write()

        new_opt = Options.from_config()
        for k, v in options.__dict__.items():
            if k == "cache":
                assert type(new_opt.cache) == type(options.cache)  # noqa: E721
            elif k == "password":
                # don't store the password in the file
                assert getattr(new_opt, k) is None
            elif k not in ("timeout", "license"):
                assert getattr(new_opt, k) == v

        assert new_opt.timeout == 1337
        assert new_opt.license == License.COMMERCIAL
Пример #4
0
 def test_from_config_section_is_not_url(self):
     with pytest.raises(NoSectionError,
                        match=r"No section: 'http://foo.bar'"):
         Options.from_config("http://foo.bar")
Пример #5
0
def options() -> "Options":
    opt = Options.from_config()
    opt.cache = None
    opt.progress_bar = False
    return opt