Path: blob/trunk/py/test/unit/selenium/webdriver/remote/remote_server_tests.py
1990 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import os18import re1920import pytest2122from selenium.webdriver.remote.server import Server232425def test_server_with_defaults():26server = Server()27assert server.host is None28assert server.port == 444429assert server.path is None30assert server.version is None31assert server.log_level == "INFO"32assert server.env is None333435def test_server_with_args():36server = Server("foo", 9999)37assert server.host == "foo"38assert server.port == 9999394041def test_server_with_kwargs():42server = Server(host="foo", port=9999, version="1.1.1", log_level="WARNING", env={"FOO": "bar"})43assert server.host == "foo"44assert server.port == 999945assert server.path is None46assert server.version == "1.1.1"47assert server.log_level == "WARNING"48assert server.env == {"FOO": "bar"}495051def test_server_with_invalid_port():52port = "invalid"53msg = f"Server.__init__() got an invalid port: '{port}'"54with pytest.raises(TypeError, match=re.escape(msg)):55Server(port=port)565758def test_server_with_port_out_of_range():59with pytest.raises(ValueError, match="port must be 0-65535"):60Server(port=99999)616263def test_server_with_bad_path():64path = "/path/to/nowhere"65msg = f"Can't find server .jar located at {path}"66with pytest.raises(OSError, match=re.escape(msg)):67Server(path=path)686970def test_server_with_invalid_version():71versions = ("0.0", "invalid")72for version in versions:73msg = f"Server.__init__() got an invalid version: '{version}'"74with pytest.raises(TypeError, match=re.escape(msg)):75Server(version=version)767778def test_server_with_invalid_log_level():79msg = ", ".join(("SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", "FINEST"))80with pytest.raises(TypeError, match=f"log_level must be one of: {msg}"):81Server(log_level="BAD")828384def test_server_with_env_os_environ():85server = Server(env=os.environ)86assert isinstance(server.env, os._Environ)878889def test_server_with_env_dict():90env = {}91server = Server(env=env)92assert isinstance(server.env, dict)93assert server.env == {}949596def test_server_with_invalid_env():97with pytest.raises(TypeError, match="env must be a mapping of environment variables"):98Server(env=[])99100101def test_stopping_server_thats_not_running():102server = Server()103with pytest.raises(RuntimeError, match="Selenium server isn't running"):104server.stop()105assert server.process is None106107108