Пример #1
0
 def test_read_config_garbage(self):
     "Tests that read_config handles a garbage file"
     handle, name = tempfile.mkstemp()
     try:
         os.write(handle, "1234"*4096)
         with pytest.raises(EnvironmentError):
             config.read_config(name)
     finally:
         os.remove(name)
Пример #2
0
    def test_read_config_port(self):
        "Tests that read_config handles a garbage file"
        conf = """[bloomd]
port = 10000
log_level = DEBUG
log_file = /tmp/testlog.log
initial_capacity = 100000
default_probability = 0.001
scale_size = 2
probability_reduction = 0.8
flush_interval = 120
"""
        handle, name = tempfile.mkstemp()
        try:
            os.write(handle, conf)
            settings = config.read_config(name)
            assert settings["port"] == 10000
            assert settings["log_level"] == "DEBUG"
            assert settings["log_file"] == "/tmp/testlog.log"
            assert settings["initial_capacity"] == 1e5
            assert settings["default_probability"] == 0.001
            assert settings["scale_size"] == 2
            assert settings["probability_reduction"] == 0.8
            assert settings["flush_interval"] == 120
        finally:
            os.remove(name)
Пример #3
0
 def test_read_config_blank(self):
     "Tests that read_config handles a blank file"
     handle, name = tempfile.mkstemp()
     try:
         os.write(handle, "")
         assert config.read_config(name) == config.DEFAULTS
     finally:
         os.remove(name)
Пример #4
0
 def test_read_config_port(self):
     "Tests that read_config handles a garbage file"
     handle, name = tempfile.mkstemp()
     try:
         os.write(handle, "[bloomd]\nport=10000\n")
         settings = config.read_config(name)
         assert settings["port"] == 10000
     finally:
         os.remove(name)
Пример #5
0
 def test_read_config_nofile(self):
     "Tests that read_config handles a missing file"
     with pytest.raises(EnvironmentError):
         config.read_config("/doesnotexist")
Пример #6
0
 def test_read_config_default(self):
     "Tests that read_config returns defaults with no args"
     assert config.read_config() == config.DEFAULTS