Example #1
0
def test_settings_read_attribute_as_int():
    clear_expectations()

    fake_config = Fake("config")
    fake_config.expects("get").with_args("name", "setting").returns("10")

    ss = SettingsSection(None, "name", fake_config)
    assert ss.as_int("setting") == 10
Example #2
0
def test_settings_read_attribute_with_no_section_returns_none():
    clear_expectations()

    fake_config = Fake("config")
    fake_config.expects("get").with_args("name", "setting_true_1").raises(NoSectionError("name"))
    fake_config.next_call("get").with_args("name", "setting_true_2").raises(NoOptionError("name", "setting_true_2"))

    ss = SettingsSection(None, "name", fake_config)
    assert not ss.as_bool("setting_true_1")
    assert not ss.as_bool("setting_true_2")
Example #3
0
def test_settings_read_attribute_as_bool():
    clear_expectations()

    fake_config = Fake("config")
    fake_config.expects("get").with_args("name", "setting_true_1").returns("True")
    fake_config.next_call("get").with_args("name", "setting_true_2").returns("true")
    fake_config.next_call("get").with_args("name", "setting_false_1").returns("False")
    fake_config.next_call("get").with_args("name", "setting_false_2").returns("false")

    ss = SettingsSection(None, "name", fake_config)
    assert ss.as_bool("setting_true_1")
    assert ss.as_bool("setting_true_2")
    assert not ss.as_bool("setting_false_1")
    assert not ss.as_bool("setting_false_2")