Skip to content

Remove pytest _describe #4429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we need the it in the tests names anymore, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I was thinking the same.
Should the naming convention be:
i) test_default_to_list or
ii) test_defaults_to_list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an english expert, but I guess 2 makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, 2 is 👍

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(),
Expand All @@ -293,7 +293,7 @@ def it_validates_is_a_list():
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(
{
Expand All @@ -308,14 +308,14 @@ def it_uses_validate_string(validate_string):
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(),
Expand All @@ -326,7 +326,7 @@ def it_validates_value():
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'}},
Expand All @@ -336,14 +336,14 @@ def it_uses_validate_bool(validate_bool):
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(),
Expand All @@ -354,7 +354,7 @@ def it_validates_value():
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'}},
Expand All @@ -364,16 +364,16 @@ def it_uses_validate_bool(validate_bool):
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(),
Expand All @@ -383,7 +383,7 @@ def it_supports_other_versions():
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(),
Expand All @@ -393,7 +393,7 @@ def it_validates_versions_out_of_range():
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(),
Expand All @@ -403,7 +403,7 @@ def it_validates_wrong_type():
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(),
Expand All @@ -422,7 +422,7 @@ def it_validates_wrong_type_right_value():
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(
Expand Down Expand Up @@ -452,7 +452,7 @@ def it_validates_env_supported_versions():
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,
}
Expand All @@ -464,42 +464,42 @@ def it_respects_default_value(value):
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()
)
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()
Expand All @@ -509,7 +509,7 @@ def cant_have_none_as_format():
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()
Expand All @@ -519,7 +519,7 @@ def formats_have_only_allowed_values():
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()
Expand All @@ -544,9 +544,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'))
Expand All @@ -560,15 +560,15 @@ def it_validates_to_abspath(tmpdir):
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()
# Test for first argument to validate_directory
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(
Expand All @@ -582,7 +582,7 @@ def it_fails_if_base_is_not_a_string(tmpdir):
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(),
Expand All @@ -596,9 +596,9 @@ def it_fails_if_base_does_not_exist(tmpdir):
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(),
Expand All @@ -611,7 +611,7 @@ def it_fails_if_build_is_invalid_option(tmpdir):
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(
{},
Expand All @@ -628,7 +628,7 @@ def it_fails_on_python_validation(tmpdir):
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(
{},
Expand All @@ -642,7 +642,7 @@ def it_works_on_python_validation(tmpdir):
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(),
Expand All @@ -653,7 +653,7 @@ def it_works(tmpdir):
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(),
Expand All @@ -666,7 +666,7 @@ def default(tmpdir):

@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,
Expand Down
Loading