From a9d7ef18fdf99ea2a69c6ef51af5cd1d69ecb2eb Mon Sep 17 00:00:00 2001 From: Tahzib Mashrik Date: Thu, 26 Jul 2018 02:35:22 +0600 Subject: [PATCH 1/4] refactor pytest-describe blocks to class --- readthedocs/config/tests/test_config.py | 84 ++++++++++----------- readthedocs/config/tests/test_validation.py | 60 +++++++-------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/readthedocs/config/tests/test_config.py b/readthedocs/config/tests/test_config.py index 3b502af44b4..62b4849555a 100644 --- a/readthedocs/config/tests/test_config.py +++ b/readthedocs/config/tests/test_config.py @@ -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 PythonExtraRequirements: - def it_defaults_to_list(): + def 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 it_validates_is_a_list(self): build = get_build_config( {'python': {'extra_requirements': 'invalid'}}, get_env_config(), @@ -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 it_uses_validate_string(self, validate_string): validate_string.return_value = True build = get_build_config( { @@ -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 ValidateUseSystemSitePackages: - def it_defaults_to_false(): + def 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 it_validates_value(self): build = get_build_config( {'python': {'use_system_site_packages': 'invalid'}}, get_env_config(), @@ -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 it_uses_validate_bool(self, validate_bool): validate_bool.return_value = True build = get_build_config( {'python': {'use_system_site_packages': 'to-validate'}}, @@ -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 ValidateSetupPyInstall: - def it_defaults_to_false(): + def 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 it_validates_value(self): build = get_build_config( {'python': {'setup_py_install': 'this-is-string'}}, get_env_config(), @@ -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 it_uses_validate_bool(self, validate_bool): validate_bool.return_value = True build = get_build_config( {'python': {'setup_py_install': 'to-validate'}}, @@ -364,16 +364,16 @@ def it_uses_validate_bool(validate_bool): validate_bool.assert_any_call('to-validate') -def describe_validate_python_version(): +class ValidateVersion: - def it_defaults_to_a_valid_version(): + def 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 it_supports_other_versions(self): build = get_build_config( {'python': {'version': 3.5}}, get_env_config(), @@ -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 it_validates_versions_out_of_range(self): build = get_build_config( {'python': {'version': 1.0}}, get_env_config(), @@ -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 it_validates_wrong_type(self): build = get_build_config( {'python': {'version': 'this-is-string'}}, get_env_config(), @@ -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 it_validates_wrong_type_right_value(self): build = get_build_config( {'python': {'version': '3.5'}}, get_env_config(), @@ -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 it_validates_env_supported_versions(self): build = get_build_config( {'python': {'version': 3.6}}, env_config=get_env_config( @@ -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 it_respects_default_value(self, value): defaults = { 'python_version': value, } @@ -464,34 +464,34 @@ def it_respects_default_value(value): assert build.python.version == value -def describe_validate_formats(): +class ValidateFormats: - def it_defaults_to_empty(): + def it_defaults_to_empty(self): build = get_build_config({}, get_env_config()) build.validate() assert build.formats == [] - def it_gets_set_correctly(): + def 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 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 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 formats_can_be_empty(self): build = get_build_config({'formats': []}, get_env_config()) build.validate() assert build.formats == [] - def all_valid_formats(): + def all_valid_formats(self): build = get_build_config( {'formats': ['pdf', 'htmlzip', 'epub']}, get_env_config() @@ -499,7 +499,7 @@ def all_valid_formats(): build.validate() assert build.formats == ['pdf', 'htmlzip', 'epub'] - def cant_have_none_as_format(): + def cant_have_none_as_format(self): build = get_build_config( {'formats': ['htmlzip', None]}, get_env_config() @@ -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 formats_have_only_allowed_values(self): build = get_build_config( {'formats': ['htmlzip', 'csv']}, get_env_config() @@ -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 only_list_type(self): build = get_build_config({'formats': 'no-list'}, get_env_config()) with raises(InvalidConfig) as excinfo: build.validate() @@ -544,9 +544,9 @@ def test_valid_build_config(): assert build.output_base -def describe_validate_base(): +class ValidateBase: - def it_validates_to_abspath(tmpdir): + def 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')) @@ -560,7 +560,7 @@ 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 it_uses_validate_directory(self, validate_directory): validate_directory.return_value = 'path' build = get_build_config({'base': '../my-path'}, get_env_config()) build.validate() @@ -568,7 +568,7 @@ def it_uses_validate_directory(validate_directory): args, kwargs = validate_directory.call_args assert args[0] == '../my-path' - def it_fails_if_base_is_not_a_string(tmpdir): + def it_fails_if_base_is_not_a_string(self, tmpdir): apply_fs(tmpdir, minimal_config) with tmpdir.as_cwd(): build = BuildConfigV1( @@ -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 it_fails_if_base_does_not_exist(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -596,9 +596,9 @@ def it_fails_if_base_does_not_exist(tmpdir): assert excinfo.value.code == INVALID_PATH -def describe_validate_build(): +class ValidateBuild: - def it_fails_if_build_is_invalid_option(tmpdir): + def it_fails_if_build_is_invalid_option(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -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 it_fails_on_python_validation(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( {}, @@ -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 it_works_on_python_validation(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( {}, @@ -642,7 +642,7 @@ def it_works_on_python_validation(tmpdir): build.validate_build() build.validate_python() - def it_works(tmpdir): + def it_works(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -653,7 +653,7 @@ def it_works(tmpdir): build.validate() assert build.build.image == 'readthedocs/build:latest' - def default(tmpdir): + def default(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -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 it_priorities_image_from_env_config(self, tmpdir, image): apply_fs(tmpdir, minimal_config) defaults = { 'build_image': image, diff --git a/readthedocs/config/tests/test_validation.py b/readthedocs/config/tests/test_validation.py index 5325aab3f62..3aa4bd864a4 100644 --- a/readthedocs/config/tests/test_validation.py +++ b/readthedocs/config/tests/test_validation.py @@ -14,28 +14,28 @@ validate_path, validate_string) -def describe_validate_bool(): - def it_accepts_true(): +class ValidateBool: + def it_accepts_true(self): assert validate_bool(True) is True - def it_accepts_false(): + def it_accepts_false(self): assert validate_bool(False) is False - def it_accepts_0(): + def it_accepts_0(self): assert validate_bool(0) is False - def it_accepts_1(): + def it_accepts_1(self): assert validate_bool(1) is True - def it_fails_on_string(): + def 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 ValidateChoice: - def it_accepts_valid_choice(): + def it_accepts_valid_choice(self): result = validate_choice('choice', ('choice', 'another_choice')) assert result is 'choice' @@ -43,15 +43,15 @@ def it_accepts_valid_choice(): validate_choice('c', 'abc') assert excinfo.value.code == INVALID_LIST - def it_rejects_invalid_choice(): + def 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 ValidateList: - def it_accepts_list_types(): + def it_accepts_list_types(self): result = validate_list(['choice', 'another_choice']) assert result == ['choice', 'another_choice'] @@ -68,15 +68,15 @@ def iterator(): validate_choice('c', 'abc') assert excinfo.value.code == INVALID_LIST - def it_rejects_string_types(): + def 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 ValidateDirectory: - def it_uses_validate_path(tmpdir): + def 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 it_uses_validate_path(tmpdir): validate_directory(path, str(tmpdir)) validate_path.assert_called_with(path, str(tmpdir)) - def it_rejects_files(tmpdir): + def 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 ValidateFile: - def it_uses_validate_path(tmpdir): + def 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 it_uses_validate_path(tmpdir): validate_file(path, str(tmpdir)) validate_path.assert_called_with(path, str(tmpdir)) - def it_rejects_directories(tmpdir): + def 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 ValidatePath: - def it_accepts_relative_path(tmpdir): + def it_accepts_relative_path(self, tmpdir): tmpdir.mkdir('a directory') validate_path('a directory', str(tmpdir)) - def it_accepts_files(tmpdir): + def it_accepts_files(self, tmpdir): tmpdir.join('file').write('content') validate_path('file', str(tmpdir)) - def it_accepts_absolute_path(tmpdir): + def 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 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 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 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 ValidateString: - def it_accepts_unicode(): + def it_accepts_unicode(self): result = validate_string(u'Unicöde') assert isinstance(result, text_type) - def it_accepts_nonunicode(): + def it_accepts_nonunicode(self): result = validate_string('Unicode') assert isinstance(result, text_type) - def it_rejects_float(): + def it_rejects_float(self): with raises(ValidationError) as excinfo: validate_string(123.456) assert excinfo.value.code == INVALID_STRING - def it_rejects_none(): + def it_rejects_none(self): with raises(ValidationError) as excinfo: validate_string(None) assert excinfo.value.code == INVALID_STRING From 674a7502bf1ab4ab9bbaff4e349ba95287ac7457 Mon Sep 17 00:00:00 2001 From: Tahzib Mashrik Date: Thu, 26 Jul 2018 01:48:29 +0600 Subject: [PATCH 2/4] upgrade requirements/testing file --- requirements/testing.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements/testing.txt b/requirements/testing.txt index d742a8f4c7f..708211c2051 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -4,9 +4,8 @@ django-dynamic-fixture==2.0.0 # 3.6.1 and >3.2.5 is incompatible # with pytest-describe 0.11.0 -pytest==3.2.5 +pytest==3.6.3 pytest-django==3.1.2 -pytest-describe==0.11.0 pytest-xdist==1.22.0 apipkg==1.4 execnet==1.5.0 From a24c303ee74fd89f8cfbc52fff4682dcf81df230 Mon Sep 17 00:00:00 2001 From: Tahzib Mashrik Date: Thu, 26 Jul 2018 02:37:01 +0600 Subject: [PATCH 3/4] small naming fix --- readthedocs/config/tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readthedocs/config/tests/test_config.py b/readthedocs/config/tests/test_config.py index 62b4849555a..fc5a5e9750a 100644 --- a/readthedocs/config/tests/test_config.py +++ b/readthedocs/config/tests/test_config.py @@ -274,7 +274,7 @@ def test_python_pip_install_default(): assert build.python.install_with_pip is False -class PythonExtraRequirements: +class ValidatePythonExtraRequirements: def it_defaults_to_list(self): build = get_build_config({'python': {}}, get_env_config()) From 7937c4bc728c6b77ee7de02bebce9ac04045c40d Mon Sep 17 00:00:00 2001 From: Tahzib Mashrik Date: Fri, 27 Jul 2018 00:33:01 +0600 Subject: [PATCH 4/4] fix test naming conventions and inherit class from object --- readthedocs/config/tests/test_config.py | 84 ++++++++++----------- readthedocs/config/tests/test_validation.py | 60 +++++++-------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/readthedocs/config/tests/test_config.py b/readthedocs/config/tests/test_config.py index fc5a5e9750a..6328cc07815 100644 --- a/readthedocs/config/tests/test_config.py +++ b/readthedocs/config/tests/test_config.py @@ -274,15 +274,15 @@ def test_python_pip_install_default(): assert build.python.install_with_pip is False -class ValidatePythonExtraRequirements: +class TestValidatePythonExtraRequirements(object): - def it_defaults_to_list(self): + 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(self): + def test_it_validates_is_a_list(self): build = get_build_config( {'python': {'extra_requirements': 'invalid'}}, get_env_config(), @@ -293,7 +293,7 @@ def it_validates_is_a_list(self): assert excinfo.value.code == PYTHON_INVALID @patch('readthedocs.config.config.validate_string') - def it_uses_validate_string(self, validate_string): + def test_it_uses_validate_string(self, validate_string): validate_string.return_value = True build = get_build_config( { @@ -308,14 +308,14 @@ def it_uses_validate_string(self, validate_string): validate_string.assert_any_call('tests') -class ValidateUseSystemSitePackages: +class TestValidateUseSystemSitePackages(object): - def it_defaults_to_false(self): + 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(self): + def test_it_validates_value(self): build = get_build_config( {'python': {'use_system_site_packages': 'invalid'}}, get_env_config(), @@ -326,7 +326,7 @@ def it_validates_value(self): excinfo.value.code = INVALID_BOOL @patch('readthedocs.config.config.validate_bool') - def it_uses_validate_bool(self, 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'}}, @@ -336,14 +336,14 @@ def it_uses_validate_bool(self, validate_bool): validate_bool.assert_any_call('to-validate') -class ValidateSetupPyInstall: +class TestValidateSetupPyInstall(object): - def it_defaults_to_false(self): + 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(self): + def test_it_validates_value(self): build = get_build_config( {'python': {'setup_py_install': 'this-is-string'}}, get_env_config(), @@ -354,7 +354,7 @@ def it_validates_value(self): assert excinfo.value.code == INVALID_BOOL @patch('readthedocs.config.config.validate_bool') - def it_uses_validate_bool(self, 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'}}, @@ -364,16 +364,16 @@ def it_uses_validate_bool(self, validate_bool): validate_bool.assert_any_call('to-validate') -class ValidateVersion: +class TestValidatePythonVersion(object): - def it_defaults_to_a_valid_version(self): + 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(self): + def test_it_supports_other_versions(self): build = get_build_config( {'python': {'version': 3.5}}, get_env_config(), @@ -383,7 +383,7 @@ def it_supports_other_versions(self): assert build.python_interpreter == 'python3.5' assert build.python_full_version == 3.5 - def it_validates_versions_out_of_range(self): + def test_it_validates_versions_out_of_range(self): build = get_build_config( {'python': {'version': 1.0}}, get_env_config(), @@ -393,7 +393,7 @@ def it_validates_versions_out_of_range(self): assert excinfo.value.key == 'python.version' assert excinfo.value.code == INVALID_CHOICE - def it_validates_wrong_type(self): + def test_it_validates_wrong_type(self): build = get_build_config( {'python': {'version': 'this-is-string'}}, get_env_config(), @@ -403,7 +403,7 @@ def it_validates_wrong_type(self): assert excinfo.value.key == 'python.version' assert excinfo.value.code == INVALID_CHOICE - def it_validates_wrong_type_right_value(self): + def test_it_validates_wrong_type_right_value(self): build = get_build_config( {'python': {'version': '3.5'}}, get_env_config(), @@ -422,7 +422,7 @@ def it_validates_wrong_type_right_value(self): assert build.python_interpreter == 'python3.5' assert build.python_full_version == 3.5 - def it_validates_env_supported_versions(self): + def test_it_validates_env_supported_versions(self): build = get_build_config( {'python': {'version': 3.6}}, env_config=get_env_config( @@ -452,7 +452,7 @@ def it_validates_env_supported_versions(self): assert build.python_full_version == 3.6 @pytest.mark.parametrize('value', [2, 3]) - def it_respects_default_value(self, value): + def test_it_respects_default_value(self, value): defaults = { 'python_version': value, } @@ -464,34 +464,34 @@ def it_respects_default_value(self, value): assert build.python.version == value -class ValidateFormats: +class TestValidateFormats(object): - def it_defaults_to_empty(self): + def test_it_defaults_to_empty(self): build = get_build_config({}, get_env_config()) build.validate() assert build.formats == [] - def it_gets_set_correctly(self): + 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(self): + 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(self): + 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(self): + def test_formats_can_be_empty(self): build = get_build_config({'formats': []}, get_env_config()) build.validate() assert build.formats == [] - def all_valid_formats(self): + def test_all_valid_formats(self): build = get_build_config( {'formats': ['pdf', 'htmlzip', 'epub']}, get_env_config() @@ -499,7 +499,7 @@ def all_valid_formats(self): build.validate() assert build.formats == ['pdf', 'htmlzip', 'epub'] - def cant_have_none_as_format(self): + def test_cant_have_none_as_format(self): build = get_build_config( {'formats': ['htmlzip', None]}, get_env_config() @@ -509,7 +509,7 @@ def cant_have_none_as_format(self): assert excinfo.value.key == 'format' assert excinfo.value.code == INVALID_CHOICE - def formats_have_only_allowed_values(self): + def test_formats_have_only_allowed_values(self): build = get_build_config( {'formats': ['htmlzip', 'csv']}, get_env_config() @@ -519,7 +519,7 @@ def formats_have_only_allowed_values(self): assert excinfo.value.key == 'format' assert excinfo.value.code == INVALID_CHOICE - def only_list_type(self): + def test_only_list_type(self): build = get_build_config({'formats': 'no-list'}, get_env_config()) with raises(InvalidConfig) as excinfo: build.validate() @@ -544,9 +544,9 @@ def test_valid_build_config(): assert build.output_base -class ValidateBase: +class TestValidateBase(object): - def it_validates_to_abspath(self, 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')) @@ -560,7 +560,7 @@ def it_validates_to_abspath(self, tmpdir): assert build.base == str(tmpdir.join('docs')) @patch('readthedocs.config.config.validate_directory') - def it_uses_validate_directory(self, 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() @@ -568,7 +568,7 @@ def it_uses_validate_directory(self, validate_directory): args, kwargs = validate_directory.call_args assert args[0] == '../my-path' - def it_fails_if_base_is_not_a_string(self, tmpdir): + def test_it_fails_if_base_is_not_a_string(self, tmpdir): apply_fs(tmpdir, minimal_config) with tmpdir.as_cwd(): build = BuildConfigV1( @@ -582,7 +582,7 @@ def it_fails_if_base_is_not_a_string(self, tmpdir): assert excinfo.value.key == 'base' assert excinfo.value.code == INVALID_STRING - def it_fails_if_base_does_not_exist(self, tmpdir): + def test_it_fails_if_base_does_not_exist(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -596,9 +596,9 @@ def it_fails_if_base_does_not_exist(self, tmpdir): assert excinfo.value.code == INVALID_PATH -class ValidateBuild: +class TestValidateBuild(object): - def it_fails_if_build_is_invalid_option(self, tmpdir): + def test_it_fails_if_build_is_invalid_option(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -611,7 +611,7 @@ def it_fails_if_build_is_invalid_option(self, tmpdir): assert excinfo.value.key == 'build' assert excinfo.value.code == INVALID_CHOICE - def it_fails_on_python_validation(self, tmpdir): + def test_it_fails_on_python_validation(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( {}, @@ -628,7 +628,7 @@ def it_fails_on_python_validation(self, tmpdir): assert excinfo.value.key == 'python.version' assert excinfo.value.code == INVALID_CHOICE - def it_works_on_python_validation(self, tmpdir): + def test_it_works_on_python_validation(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( {}, @@ -642,7 +642,7 @@ def it_works_on_python_validation(self, tmpdir): build.validate_build() build.validate_python() - def it_works(self, tmpdir): + def test_it_works(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -653,7 +653,7 @@ def it_works(self, tmpdir): build.validate() assert build.build.image == 'readthedocs/build:latest' - def default(self, tmpdir): + def test_default(self, tmpdir): apply_fs(tmpdir, minimal_config) build = BuildConfigV1( get_env_config(), @@ -666,7 +666,7 @@ def default(self, tmpdir): @pytest.mark.parametrize( 'image', ['latest', 'readthedocs/build:3.0', 'rtd/build:latest']) - def it_priorities_image_from_env_config(self, tmpdir, image): + def test_it_priorities_image_from_env_config(self, tmpdir, image): apply_fs(tmpdir, minimal_config) defaults = { 'build_image': image, diff --git a/readthedocs/config/tests/test_validation.py b/readthedocs/config/tests/test_validation.py index 3aa4bd864a4..8c2519570d2 100644 --- a/readthedocs/config/tests/test_validation.py +++ b/readthedocs/config/tests/test_validation.py @@ -14,28 +14,28 @@ validate_path, validate_string) -class ValidateBool: - def it_accepts_true(self): +class TestValidateBool(object): + def test_it_accepts_true(self): assert validate_bool(True) is True - def it_accepts_false(self): + def test_it_accepts_false(self): assert validate_bool(False) is False - def it_accepts_0(self): + def test_it_accepts_0(self): assert validate_bool(0) is False - def it_accepts_1(self): + def test_it_accepts_1(self): assert validate_bool(1) is True - def it_fails_on_string(self): + def test_it_fails_on_string(self): with raises(ValidationError) as excinfo: validate_bool('random string') assert excinfo.value.code == INVALID_BOOL -class ValidateChoice: +class TestValidateChoice(object): - def it_accepts_valid_choice(self): + def test_it_accepts_valid_choice(self): result = validate_choice('choice', ('choice', 'another_choice')) assert result is 'choice' @@ -43,15 +43,15 @@ def it_accepts_valid_choice(self): validate_choice('c', 'abc') assert excinfo.value.code == INVALID_LIST - def it_rejects_invalid_choice(self): + 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 -class ValidateList: +class TestValidateList(object): - def it_accepts_list_types(self): + def test_it_accepts_list_types(self): result = validate_list(['choice', 'another_choice']) assert result == ['choice', 'another_choice'] @@ -68,15 +68,15 @@ def iterator(): validate_choice('c', 'abc') assert excinfo.value.code == INVALID_LIST - def it_rejects_string_types(self): + def test_it_rejects_string_types(self): with raises(ValidationError) as excinfo: result = validate_list('choice') assert excinfo.value.code == INVALID_LIST -class ValidateDirectory: +class TestValidateDirectory(object): - def it_uses_validate_path(self, 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 it_uses_validate_path(self, tmpdir): validate_directory(path, str(tmpdir)) validate_path.assert_called_with(path, str(tmpdir)) - def it_rejects_files(self, 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 -class ValidateFile: +class TestValidateFile(object): - def it_uses_validate_path(self, 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 it_uses_validate_path(self, tmpdir): validate_file(path, str(tmpdir)) validate_path.assert_called_with(path, str(tmpdir)) - def it_rejects_directories(self, 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 -class ValidatePath: +class TestValidatePath(object): - def it_accepts_relative_path(self, tmpdir): + def test_it_accepts_relative_path(self, tmpdir): tmpdir.mkdir('a directory') validate_path('a directory', str(tmpdir)) - def it_accepts_files(self, tmpdir): + def test_it_accepts_files(self, tmpdir): tmpdir.join('file').write('content') validate_path('file', str(tmpdir)) - def it_accepts_absolute_path(self, 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(self, 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(self): + 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(self, 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 -class ValidateString: +class TestValidateString(object): - def it_accepts_unicode(self): + def test_it_accepts_unicode(self): result = validate_string(u'Unicöde') assert isinstance(result, text_type) - def it_accepts_nonunicode(self): + def test_it_accepts_nonunicode(self): result = validate_string('Unicode') assert isinstance(result, text_type) - def it_rejects_float(self): + 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(self): + def test_it_rejects_none(self): with raises(ValidationError) as excinfo: validate_string(None) assert excinfo.value.code == INVALID_STRING