Merge pull request #4429 from mashrikt/pytest_describe_remove

Remove pytest _describe
add-modified-date-importedfile
Eric Holscher 2018-10-31 10:31:49 -05:00 committed by GitHub
commit 4984776dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 73 deletions

View File

@ -295,15 +295,15 @@ def test_python_pip_install_default():
assert build.python.install_with_pip is False
def describe_validate_python_extra_requirements():
class TestValidatePythonExtraRequirements(object):
def it_defaults_to_list():
def test_it_defaults_to_list(self):
build = get_build_config({'python': {}}, get_env_config())
build.validate()
# Default is an empty list.
assert build.python.extra_requirements == []
def it_validates_is_a_list():
def test_it_validates_is_a_list(self):
build = get_build_config(
{'python': {'extra_requirements': 'invalid'}},
get_env_config(),
@ -314,7 +314,7 @@ def describe_validate_python_extra_requirements():
assert excinfo.value.code == PYTHON_INVALID
@patch('readthedocs.config.config.validate_string')
def it_uses_validate_string(validate_string):
def test_it_uses_validate_string(self, validate_string):
validate_string.return_value = True
build = get_build_config(
{
@ -329,14 +329,14 @@ def describe_validate_python_extra_requirements():
validate_string.assert_any_call('tests')
def describe_validate_use_system_site_packages():
class TestValidateUseSystemSitePackages(object):
def it_defaults_to_false():
def test_it_defaults_to_false(self):
build = get_build_config({'python': {}}, get_env_config())
build.validate()
assert build.python.use_system_site_packages is False
def it_validates_value():
def test_it_validates_value(self):
build = get_build_config(
{'python': {'use_system_site_packages': 'invalid'}},
get_env_config(),
@ -347,7 +347,7 @@ def describe_validate_use_system_site_packages():
excinfo.value.code = INVALID_BOOL
@patch('readthedocs.config.config.validate_bool')
def it_uses_validate_bool(validate_bool):
def test_it_uses_validate_bool(self, validate_bool):
validate_bool.return_value = True
build = get_build_config(
{'python': {'use_system_site_packages': 'to-validate'}},
@ -357,14 +357,14 @@ def describe_validate_use_system_site_packages():
validate_bool.assert_any_call('to-validate')
def describe_validate_setup_py_install():
class TestValidateSetupPyInstall(object):
def it_defaults_to_false():
def test_it_defaults_to_false(self):
build = get_build_config({'python': {}}, get_env_config())
build.validate()
assert build.python.install_with_setup is False
def it_validates_value():
def test_it_validates_value(self):
build = get_build_config(
{'python': {'setup_py_install': 'this-is-string'}},
get_env_config(),
@ -375,7 +375,7 @@ def describe_validate_setup_py_install():
assert excinfo.value.code == INVALID_BOOL
@patch('readthedocs.config.config.validate_bool')
def it_uses_validate_bool(validate_bool):
def test_it_uses_validate_bool(self, validate_bool):
validate_bool.return_value = True
build = get_build_config(
{'python': {'setup_py_install': 'to-validate'}},
@ -385,16 +385,16 @@ def describe_validate_setup_py_install():
validate_bool.assert_any_call('to-validate')
def describe_validate_python_version():
class TestValidatePythonVersion(object):
def it_defaults_to_a_valid_version():
def test_it_defaults_to_a_valid_version(self):
build = get_build_config({'python': {}}, get_env_config())
build.validate()
assert build.python.version == 2
assert build.python_interpreter == 'python2.7'
assert build.python_full_version == 2.7
def it_supports_other_versions():
def test_it_supports_other_versions(self):
build = get_build_config(
{'python': {'version': 3.5}},
get_env_config(),
@ -404,7 +404,7 @@ def describe_validate_python_version():
assert build.python_interpreter == 'python3.5'
assert build.python_full_version == 3.5
def it_validates_versions_out_of_range():
def test_it_validates_versions_out_of_range(self):
build = get_build_config(
{'python': {'version': 1.0}},
get_env_config(),
@ -414,7 +414,7 @@ def describe_validate_python_version():
assert excinfo.value.key == 'python.version'
assert excinfo.value.code == INVALID_CHOICE
def it_validates_wrong_type():
def test_it_validates_wrong_type(self):
build = get_build_config(
{'python': {'version': 'this-is-string'}},
get_env_config(),
@ -424,7 +424,7 @@ def describe_validate_python_version():
assert excinfo.value.key == 'python.version'
assert excinfo.value.code == INVALID_CHOICE
def it_validates_wrong_type_right_value():
def test_it_validates_wrong_type_right_value(self):
build = get_build_config(
{'python': {'version': '3.5'}},
get_env_config(),
@ -443,7 +443,7 @@ def describe_validate_python_version():
assert build.python_interpreter == 'python3.5'
assert build.python_full_version == 3.5
def it_validates_env_supported_versions():
def test_it_validates_env_supported_versions(self):
build = get_build_config(
{'python': {'version': 3.6}},
env_config=get_env_config(
@ -473,7 +473,7 @@ def describe_validate_python_version():
assert build.python_full_version == 3.6
@pytest.mark.parametrize('value', [2, 3])
def it_respects_default_value(value):
def test_it_respects_default_value(self, value):
defaults = {
'python_version': value,
}
@ -485,34 +485,34 @@ def describe_validate_python_version():
assert build.python.version == value
def describe_validate_formats():
class TestValidateFormats(object):
def it_defaults_to_empty():
def test_it_defaults_to_empty(self):
build = get_build_config({}, get_env_config())
build.validate()
assert build.formats == []
def it_gets_set_correctly():
def test_it_gets_set_correctly(self):
build = get_build_config({'formats': ['pdf']}, get_env_config())
build.validate()
assert build.formats == ['pdf']
def formats_can_be_null():
def test_formats_can_be_null(self):
build = get_build_config({'formats': None}, get_env_config())
build.validate()
assert build.formats == []
def formats_with_previous_none():
def test_formats_with_previous_none(self):
build = get_build_config({'formats': ['none']}, get_env_config())
build.validate()
assert build.formats == []
def formats_can_be_empty():
def test_formats_can_be_empty(self):
build = get_build_config({'formats': []}, get_env_config())
build.validate()
assert build.formats == []
def all_valid_formats():
def test_all_valid_formats(self):
build = get_build_config(
{'formats': ['pdf', 'htmlzip', 'epub']},
get_env_config()
@ -520,7 +520,7 @@ def describe_validate_formats():
build.validate()
assert build.formats == ['pdf', 'htmlzip', 'epub']
def cant_have_none_as_format():
def test_cant_have_none_as_format(self):
build = get_build_config(
{'formats': ['htmlzip', None]},
get_env_config()
@ -530,7 +530,7 @@ def describe_validate_formats():
assert excinfo.value.key == 'format'
assert excinfo.value.code == INVALID_CHOICE
def formats_have_only_allowed_values():
def test_formats_have_only_allowed_values(self):
build = get_build_config(
{'formats': ['htmlzip', 'csv']},
get_env_config()
@ -540,7 +540,7 @@ def describe_validate_formats():
assert excinfo.value.key == 'format'
assert excinfo.value.code == INVALID_CHOICE
def only_list_type():
def test_only_list_type(self):
build = get_build_config({'formats': 'no-list'}, get_env_config())
with raises(InvalidConfig) as excinfo:
build.validate()
@ -565,9 +565,9 @@ def test_valid_build_config():
assert build.output_base
def describe_validate_base():
class TestValidateBase(object):
def it_validates_to_abspath(tmpdir):
def test_it_validates_to_abspath(self, tmpdir):
apply_fs(tmpdir, {'configs': minimal_config, 'docs': {}})
with tmpdir.as_cwd():
source_file = str(tmpdir.join('configs', 'readthedocs.yml'))
@ -581,7 +581,7 @@ def describe_validate_base():
assert build.base == str(tmpdir.join('docs'))
@patch('readthedocs.config.config.validate_directory')
def it_uses_validate_directory(validate_directory):
def test_it_uses_validate_directory(self, validate_directory):
validate_directory.return_value = 'path'
build = get_build_config({'base': '../my-path'}, get_env_config())
build.validate()
@ -589,7 +589,7 @@ def describe_validate_base():
args, kwargs = validate_directory.call_args
assert args[0] == '../my-path'
def it_fails_if_base_is_not_a_string(tmpdir):
def test_it_fails_if_base_is_not_a_string(self, tmpdir):
apply_fs(tmpdir, minimal_config)
with tmpdir.as_cwd():
build = BuildConfigV1(
@ -603,7 +603,7 @@ def describe_validate_base():
assert excinfo.value.key == 'base'
assert excinfo.value.code == INVALID_STRING
def it_fails_if_base_does_not_exist(tmpdir):
def test_it_fails_if_base_does_not_exist(self, tmpdir):
apply_fs(tmpdir, minimal_config)
build = BuildConfigV1(
get_env_config(),
@ -617,9 +617,9 @@ def describe_validate_base():
assert excinfo.value.code == INVALID_PATH
def describe_validate_build():
class TestValidateBuild(object):
def it_fails_if_build_is_invalid_option(tmpdir):
def test_it_fails_if_build_is_invalid_option(self, tmpdir):
apply_fs(tmpdir, minimal_config)
build = BuildConfigV1(
get_env_config(),
@ -632,7 +632,7 @@ def describe_validate_build():
assert excinfo.value.key == 'build'
assert excinfo.value.code == INVALID_CHOICE
def it_fails_on_python_validation(tmpdir):
def test_it_fails_on_python_validation(self, tmpdir):
apply_fs(tmpdir, minimal_config)
build = BuildConfigV1(
{},
@ -649,7 +649,7 @@ def describe_validate_build():
assert excinfo.value.key == 'python.version'
assert excinfo.value.code == INVALID_CHOICE
def it_works_on_python_validation(tmpdir):
def test_it_works_on_python_validation(self, tmpdir):
apply_fs(tmpdir, minimal_config)
build = BuildConfigV1(
{},
@ -663,7 +663,7 @@ def describe_validate_build():
build.validate_build()
build.validate_python()
def it_works(tmpdir):
def test_it_works(self, tmpdir):
apply_fs(tmpdir, minimal_config)
build = BuildConfigV1(
get_env_config(),
@ -674,7 +674,7 @@ def describe_validate_build():
build.validate()
assert build.build.image == 'readthedocs/build:latest'
def default(tmpdir):
def test_default(self, tmpdir):
apply_fs(tmpdir, minimal_config)
build = BuildConfigV1(
get_env_config(),
@ -687,7 +687,7 @@ def describe_validate_build():
@pytest.mark.parametrize(
'image', ['latest', 'readthedocs/build:3.0', 'rtd/build:latest'])
def it_priorities_image_from_env_config(tmpdir, image):
def test_it_priorities_image_from_env_config(self, tmpdir, image):
apply_fs(tmpdir, minimal_config)
defaults = {
'build_image': image,

View File

@ -14,28 +14,28 @@ from readthedocs.config.validation import (
validate_path, validate_string)
def describe_validate_bool():
def it_accepts_true():
class TestValidateBool(object):
def test_it_accepts_true(self):
assert validate_bool(True) is True
def it_accepts_false():
def test_it_accepts_false(self):
assert validate_bool(False) is False
def it_accepts_0():
def test_it_accepts_0(self):
assert validate_bool(0) is False
def it_accepts_1():
def test_it_accepts_1(self):
assert validate_bool(1) is True
def it_fails_on_string():
def test_it_fails_on_string(self):
with raises(ValidationError) as excinfo:
validate_bool('random string')
assert excinfo.value.code == INVALID_BOOL
def describe_validate_choice():
class TestValidateChoice(object):
def it_accepts_valid_choice():
def test_it_accepts_valid_choice(self):
result = validate_choice('choice', ('choice', 'another_choice'))
assert result is 'choice'
@ -43,15 +43,15 @@ def describe_validate_choice():
validate_choice('c', 'abc')
assert excinfo.value.code == INVALID_LIST
def it_rejects_invalid_choice():
def test_it_rejects_invalid_choice(self):
with raises(ValidationError) as excinfo:
validate_choice('not-a-choice', ('choice', 'another_choice'))
assert excinfo.value.code == INVALID_CHOICE
def describe_validate_list():
class TestValidateList(object):
def it_accepts_list_types():
def test_it_accepts_list_types(self):
result = validate_list(['choice', 'another_choice'])
assert result == ['choice', 'another_choice']
@ -68,15 +68,15 @@ def describe_validate_list():
validate_choice('c', 'abc')
assert excinfo.value.code == INVALID_LIST
def it_rejects_string_types():
def test_it_rejects_string_types(self):
with raises(ValidationError) as excinfo:
result = validate_list('choice')
assert excinfo.value.code == INVALID_LIST
def describe_validate_directory():
class TestValidateDirectory(object):
def it_uses_validate_path(tmpdir):
def test_it_uses_validate_path(self, tmpdir):
patcher = patch('readthedocs.config.validation.validate_path')
with patcher as validate_path:
path = text_type(tmpdir.mkdir('a directory'))
@ -84,16 +84,16 @@ def describe_validate_directory():
validate_directory(path, str(tmpdir))
validate_path.assert_called_with(path, str(tmpdir))
def it_rejects_files(tmpdir):
def test_it_rejects_files(self, tmpdir):
tmpdir.join('file').write('content')
with raises(ValidationError) as excinfo:
validate_directory('file', str(tmpdir))
assert excinfo.value.code == INVALID_DIRECTORY
def describe_validate_file():
class TestValidateFile(object):
def it_uses_validate_path(tmpdir):
def test_it_uses_validate_path(self, tmpdir):
patcher = patch('readthedocs.config.validation.validate_path')
with patcher as validate_path:
path = tmpdir.join('a file')
@ -103,59 +103,59 @@ def describe_validate_file():
validate_file(path, str(tmpdir))
validate_path.assert_called_with(path, str(tmpdir))
def it_rejects_directories(tmpdir):
def test_it_rejects_directories(self, tmpdir):
tmpdir.mkdir('directory')
with raises(ValidationError) as excinfo:
validate_file('directory', str(tmpdir))
assert excinfo.value.code == INVALID_FILE
def describe_validate_path():
class TestValidatePath(object):
def it_accepts_relative_path(tmpdir):
def test_it_accepts_relative_path(self, tmpdir):
tmpdir.mkdir('a directory')
validate_path('a directory', str(tmpdir))
def it_accepts_files(tmpdir):
def test_it_accepts_files(self, tmpdir):
tmpdir.join('file').write('content')
validate_path('file', str(tmpdir))
def it_accepts_absolute_path(tmpdir):
def test_it_accepts_absolute_path(self, tmpdir):
path = str(tmpdir.mkdir('a directory'))
validate_path(path, 'does not matter')
def it_returns_absolute_path(tmpdir):
def test_it_returns_absolute_path(self, tmpdir):
tmpdir.mkdir('a directory')
path = validate_path('a directory', str(tmpdir))
assert path == os.path.abspath(path)
def it_only_accepts_strings():
def test_it_only_accepts_strings(self):
with raises(ValidationError) as excinfo:
validate_path(None, '')
assert excinfo.value.code == INVALID_STRING
def it_rejects_non_existent_path(tmpdir):
def test_it_rejects_non_existent_path(self, tmpdir):
with raises(ValidationError) as excinfo:
validate_path('does not exist', str(tmpdir))
assert excinfo.value.code == INVALID_PATH
def describe_validate_string():
class TestValidateString(object):
def it_accepts_unicode():
def test_it_accepts_unicode(self):
result = validate_string(u'Unicöde')
assert isinstance(result, text_type)
def it_accepts_nonunicode():
def test_it_accepts_nonunicode(self):
result = validate_string('Unicode')
assert isinstance(result, text_type)
def it_rejects_float():
def test_it_rejects_float(self):
with raises(ValidationError) as excinfo:
validate_string(123.456)
assert excinfo.value.code == INVALID_STRING
def it_rejects_none():
def test_it_rejects_none(self):
with raises(ValidationError) as excinfo:
validate_string(None)
assert excinfo.value.code == INVALID_STRING

View File

@ -3,7 +3,6 @@
django-dynamic-fixture==2.0.0
pytest==3.7.4
pytest-django==3.4.2
pytest-describe==0.11.1
pytest-xdist==1.23.0
pytest-cov
apipkg==1.5