Use double quotes
This commit is contained in:
parent
7b32ffc599
commit
ea8f1a13e3
1 changed files with 2464 additions and 2466 deletions
|
|
@ -7,123 +7,123 @@ import pytest
|
|||
from velofy import configuration
|
||||
|
||||
|
||||
envs = ['production', 'testing']
|
||||
envs = ["production", "testing"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_config_repr(env):
|
||||
"""Config objects have the text representation '<configuration>'."""
|
||||
config = configuration.make_config(env)
|
||||
|
||||
assert str(config) == '<configuration>'
|
||||
assert str(config) == "<configuration>"
|
||||
|
||||
|
||||
def test_invalid_config():
|
||||
"""There are only 'production' and 'testing' configurations."""
|
||||
with pytest.raises(ValueError, match="'production' or 'testing'"):
|
||||
configuration.make_config('invalid')
|
||||
configuration.make_config("invalid")
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_database_uri_set(env, monkeypatch):
|
||||
"""Package does NOT emit warning if DATABASE_URI is set."""
|
||||
uri = 'postgresql://user:password@localhost/db'
|
||||
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', uri)
|
||||
monkeypatch.setattr(configuration.TestingConfig, 'DATABASE_URI', uri)
|
||||
uri = "postgresql://user:password@localhost/db"
|
||||
monkeypatch.setattr(configuration.ProductionConfig, "DATABASE_URI", uri)
|
||||
monkeypatch.setattr(configuration.TestingConfig, "DATABASE_URI", uri)
|
||||
|
||||
# Prevent that a warning is emitted for a missing R_LIBS_PATH.
|
||||
monkeypatch.setattr(configuration.Config, 'R_LIBS_PATH', '.cache/r_libs')
|
||||
monkeypatch.setattr(configuration.Config, "R_LIBS_PATH", ".cache/r_libs")
|
||||
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
warnings.simplefilter('always')
|
||||
warnings.simplefilter("always")
|
||||
configuration.make_config(env)
|
||||
|
||||
assert len(record) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_no_database_uri_set_with_testing_env_var(env, monkeypatch):
|
||||
"""Package does not work without DATABASE_URI set in the environment."""
|
||||
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', None)
|
||||
monkeypatch.setattr(configuration.TestingConfig, 'DATABASE_URI', None)
|
||||
monkeypatch.setattr(configuration.ProductionConfig, "DATABASE_URI", None)
|
||||
monkeypatch.setattr(configuration.TestingConfig, "DATABASE_URI", None)
|
||||
|
||||
monkeypatch.setenv('TESTING', 'true')
|
||||
monkeypatch.setenv("TESTING", "true")
|
||||
|
||||
# Prevent that a warning is emitted for a missing R_LIBS_PATH.
|
||||
monkeypatch.setattr(configuration.Config, 'R_LIBS_PATH', '.cache/r_libs')
|
||||
monkeypatch.setattr(configuration.Config, "R_LIBS_PATH", ".cache/r_libs")
|
||||
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
warnings.simplefilter('always')
|
||||
warnings.simplefilter("always")
|
||||
configuration.make_config(env)
|
||||
|
||||
assert len(record) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_no_database_uri_set_without_testing_env_var(env, monkeypatch):
|
||||
"""Package does not work without DATABASE_URI set in the environment."""
|
||||
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', None)
|
||||
monkeypatch.setattr(configuration.TestingConfig, 'DATABASE_URI', None)
|
||||
monkeypatch.setattr(configuration.ProductionConfig, "DATABASE_URI", None)
|
||||
monkeypatch.setattr(configuration.TestingConfig, "DATABASE_URI", None)
|
||||
|
||||
monkeypatch.delenv('TESTING', raising=False)
|
||||
monkeypatch.delenv("TESTING", raising=False)
|
||||
|
||||
# Prevent that a warning is emitted for a missing R_LIBS_PATH.
|
||||
monkeypatch.setattr(configuration.Config, 'R_LIBS_PATH', '.cache/r_libs')
|
||||
monkeypatch.setattr(configuration.Config, "R_LIBS_PATH", ".cache/r_libs")
|
||||
|
||||
with pytest.warns(UserWarning, match='no DATABASE_URI'):
|
||||
with pytest.warns(UserWarning, match="no DATABASE_URI"):
|
||||
configuration.make_config(env)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_r_libs_path_set(env, monkeypatch):
|
||||
"""Package does NOT emit a warning if R_LIBS is set in the environment."""
|
||||
monkeypatch.setattr(configuration.Config, 'R_LIBS_PATH', '.cache/r_libs')
|
||||
monkeypatch.setattr(configuration.Config, "R_LIBS_PATH", ".cache/r_libs")
|
||||
|
||||
# Prevent that a warning is emitted for a missing DATABASE_URI.
|
||||
uri = 'postgresql://user:password@localhost/db'
|
||||
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', uri)
|
||||
uri = "postgresql://user:password@localhost/db"
|
||||
monkeypatch.setattr(configuration.ProductionConfig, "DATABASE_URI", uri)
|
||||
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
warnings.simplefilter('always')
|
||||
warnings.simplefilter("always")
|
||||
configuration.make_config(env)
|
||||
|
||||
assert len(record) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_no_r_libs_path_set_with_testing_env_var(env, monkeypatch):
|
||||
"""Package emits a warning if no R_LIBS is set in the environment ...
|
||||
|
||||
... when not testing.
|
||||
"""
|
||||
monkeypatch.setattr(configuration.Config, 'R_LIBS_PATH', None)
|
||||
monkeypatch.setenv('TESTING', 'true')
|
||||
monkeypatch.setattr(configuration.Config, "R_LIBS_PATH", None)
|
||||
monkeypatch.setenv("TESTING", "true")
|
||||
|
||||
# Prevent that a warning is emitted for a missing DATABASE_URI.
|
||||
uri = 'postgresql://user:password@localhost/db'
|
||||
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', uri)
|
||||
uri = "postgresql://user:password@localhost/db"
|
||||
monkeypatch.setattr(configuration.ProductionConfig, "DATABASE_URI", uri)
|
||||
|
||||
with warnings.catch_warnings(record=True) as record:
|
||||
warnings.simplefilter('always')
|
||||
warnings.simplefilter("always")
|
||||
configuration.make_config(env)
|
||||
|
||||
assert len(record) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('env', envs)
|
||||
@pytest.mark.parametrize("env", envs)
|
||||
def test_no_r_libs_path_set_without_testing_env_var(env, monkeypatch):
|
||||
"""Package emits a warning if no R_LIBS is set in the environment ...
|
||||
|
||||
... when not testing.
|
||||
"""
|
||||
monkeypatch.setattr(configuration.Config, 'R_LIBS_PATH', None)
|
||||
monkeypatch.delenv('TESTING', raising=False)
|
||||
monkeypatch.setattr(configuration.Config, "R_LIBS_PATH", None)
|
||||
monkeypatch.delenv("TESTING", raising=False)
|
||||
|
||||
# Prevent that a warning is emitted for a missing DATABASE_URI.
|
||||
uri = 'postgresql://user:password@localhost/db'
|
||||
monkeypatch.setattr(configuration.ProductionConfig, 'DATABASE_URI', uri)
|
||||
uri = "postgresql://user:password@localhost/db"
|
||||
monkeypatch.setattr(configuration.ProductionConfig, "DATABASE_URI", uri)
|
||||
|
||||
with pytest.warns(UserWarning, match='no R_LIBS'):
|
||||
with pytest.warns(UserWarning, match="no R_LIBS"):
|
||||
configuration.make_config(env)
|
||||
|
||||
|
||||
|
|
@ -132,5 +132,5 @@ def test_random_testing_schema():
|
|||
result = configuration.random_schema_name()
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert result.startswith('temp_')
|
||||
assert result.startswith("temp_")
|
||||
assert len(result) == 15
|
||||
|
|
|
|||
Loading…
Reference in a new issue