Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Oct 24, 2018
1 parent 8de5432 commit cc9eab1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 86 deletions.
69 changes: 8 additions & 61 deletions readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
ConfigError,
ConfigOptionNotSupportedError,
InvalidConfig,
ProjectConfig,
load,
)
from readthedocs.config.config import (
Expand Down Expand Up @@ -81,13 +80,11 @@
}


def get_build_config(config, env_config=None, source_file='readthedocs.yml',
source_position=0):
def get_build_config(config, env_config=None, source_file='readthedocs.yml'):
return BuildConfigV1(
env_config or {},
config,
source_file=source_file,
source_position=source_position,
)


Expand Down Expand Up @@ -131,10 +128,7 @@ def test_load_empty_config_file(tmpdir):
def test_minimal_config(tmpdir):
apply_fs(tmpdir, minimal_config_dir)
base = str(tmpdir)
config = load(base, env_config)
assert isinstance(config, ProjectConfig)
assert len(config) == 1
build = config[0]
build = load(base, env_config)
assert isinstance(build, BuildConfigV1)


Expand All @@ -145,10 +139,7 @@ def test_load_version1(tmpdir):
''')
})
base = str(tmpdir)
config = load(base, get_env_config({'allow_v2': True}))
assert isinstance(config, ProjectConfig)
assert len(config) == 1
build = config[0]
build = load(base, get_env_config({'allow_v2': True}))
assert isinstance(build, BuildConfigV1)


Expand All @@ -159,10 +150,7 @@ def test_load_version2(tmpdir):
''')
})
base = str(tmpdir)
config = load(base, get_env_config({'allow_v2': True}))
assert isinstance(config, ProjectConfig)
assert len(config) == 1
build = config[0]
build = load(base, get_env_config({'allow_v2': True}))
assert isinstance(build, BuildConfigV2)


Expand All @@ -183,31 +171,18 @@ def test_yaml_extension(tmpdir):
apply_fs(tmpdir, yaml_extension_config_dir)
base = str(tmpdir)
config = load(base, env_config)
assert len(config) == 1
assert isinstance(config, BuildConfigV1)


def test_build_config_has_source_file(tmpdir):
base = str(apply_fs(tmpdir, minimal_config_dir))
build = load(base, env_config)[0]
build = load(base, env_config)
assert build.source_file == os.path.join(base, 'readthedocs.yml')
assert build.source_position == 0


def test_build_config_has_source_position(tmpdir):
base = str(apply_fs(tmpdir, multiple_config_dir))
builds = load(base, env_config)
assert len(builds) == 2
first, second = filter(
lambda b: not b.source_file.endswith('nested/readthedocs.yml'),
builds,
)
assert first.source_position == 0
assert second.source_position == 1


def test_build_config_has_list_with_single_empty_value(tmpdir):
base = str(apply_fs(tmpdir, config_with_explicit_empty_list))
build = load(base, env_config)[0]
build = load(base, env_config)
assert isinstance(build, BuildConfigV1)
assert build.formats == []

Expand All @@ -217,7 +192,6 @@ def test_config_requires_name():
{'output_base': ''},
{},
source_file='readthedocs.yml',
source_position=0,
)
with raises(InvalidConfig) as excinfo:
build.validate()
Expand All @@ -230,7 +204,6 @@ def test_build_requires_valid_name():
{'output_base': ''},
{'name': 'with/slashes'},
source_file='readthedocs.yml',
source_position=0,
)
with raises(InvalidConfig) as excinfo:
build.validate()
Expand Down Expand Up @@ -554,7 +527,6 @@ def test_valid_build_config():
env_config,
minimal_config,
source_file='readthedocs.yml',
source_position=0,
)
build.validate()
assert build.name == 'docs'
Expand All @@ -576,7 +548,6 @@ def it_validates_to_abspath(tmpdir):
get_env_config(),
{'base': '../docs'},
source_file=source_file,
source_position=0,
)
build.validate()
assert build.base == str(tmpdir.join('docs'))
Expand All @@ -597,7 +568,6 @@ def it_fails_if_base_is_not_a_string(tmpdir):
get_env_config(),
{'base': 1},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
with raises(InvalidConfig) as excinfo:
build.validate()
Expand All @@ -610,7 +580,6 @@ def it_fails_if_base_does_not_exist(tmpdir):
get_env_config(),
{'base': 'docs'},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
with raises(InvalidConfig) as excinfo:
build.validate()
Expand All @@ -626,7 +595,6 @@ def it_fails_if_build_is_invalid_option(tmpdir):
get_env_config(),
{'build': {'image': 3.0}},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
with raises(InvalidConfig) as excinfo:
build.validate()
Expand All @@ -642,7 +610,6 @@ def it_fails_on_python_validation(tmpdir):
'python': {'version': '3.3'},
},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
build.validate_build()
with raises(InvalidConfig) as excinfo:
Expand All @@ -659,7 +626,6 @@ def it_works_on_python_validation(tmpdir):
'python': {'version': '3.3'},
},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
build.validate_build()
build.validate_python()
Expand All @@ -670,7 +636,6 @@ def it_works(tmpdir):
get_env_config(),
{'build': {'image': 'latest'}},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
build.validate()
assert build.build.image == 'readthedocs/build:latest'
Expand All @@ -681,7 +646,6 @@ def default(tmpdir):
get_env_config(),
{},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
build.validate()
assert build.build.image == 'readthedocs/build:2.0'
Expand All @@ -697,7 +661,6 @@ def it_priorities_image_from_env_config(tmpdir, image):
get_env_config({'defaults': defaults}),
{'build': {'image': 'latest'}},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
build.validate()
assert build.build.image == image
Expand Down Expand Up @@ -787,7 +750,6 @@ def test_build_validate_calls_all_subvalidators(tmpdir):
{},
{},
source_file=str(tmpdir.join('readthedocs.yml')),
source_position=0,
)
with patch.multiple(
BuildConfigV1,
Expand All @@ -803,20 +765,6 @@ def test_build_validate_calls_all_subvalidators(tmpdir):
BuildConfigV1.validate_output_base.assert_called_with()


def test_validate_project_config():
with patch.object(BuildConfigV1, 'validate') as build_validate:
project = ProjectConfig([
BuildConfigV1(
env_config,
minimal_config,
source_file='readthedocs.yml',
source_position=0,
),
])
project.validate()
assert build_validate.call_count == 1


def test_load_calls_validate(tmpdir):
apply_fs(tmpdir, minimal_config_dir)
base = str(tmpdir)
Expand Down Expand Up @@ -844,12 +792,11 @@ def test_config_filenames_regex(correct_config_filename):
class TestBuildConfigV2(object):

def get_build_config(self, config, env_config=None,
source_file='readthedocs.yml', source_position=0):
source_file='readthedocs.yml'):
return BuildConfigV2(
env_config or {},
config,
source_file=source_file,
source_position=source_position,
)

def test_version(self):
Expand Down
22 changes: 9 additions & 13 deletions readthedocs/config/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,35 @@ def test_parse_bad_type():
def test_parse_single_config():
buf = StringIO(u'base: path')
config = parse(buf)
assert isinstance(config, list)
assert len(config) == 1
assert config[0]['base'] == 'path'
assert isinstance(config, dict)
assert config['base'] == 'path'


def test_parse_null_value():
buf = StringIO(u'base: null')
config = parse(buf)
assert config[0]['base'] is None
assert config['base'] is None


def test_parse_empty_value():
buf = StringIO(u'base:')
config = parse(buf)
assert config[0]['base'] is None
assert config['base'] is None


def test_parse_empty_string_value():
buf = StringIO(u'base: ""')
config = parse(buf)
assert config[0]['base'] == ''
assert config['base'] == ''


def test_parse_empty_list():
buf = StringIO(u'base: []')
config = parse(buf)
assert config[0]['base'] == []
assert config['base'] == []


def test_parse_multiple_configs_in_one_file():
def test_do_not_parse_multiple_configs_in_one_file():
buf = StringIO(
u'''
base: path
Expand All @@ -67,8 +66,5 @@ def test_parse_multiple_configs_in_one_file():
nested:
works: true
''')
configs = parse(buf)
assert isinstance(configs, list)
assert len(configs) == 2
assert configs[0]['base'] == 'path'
assert configs[1]['nested'] == {'works': True}
with raises(ParseError):
parse(buf)
19 changes: 7 additions & 12 deletions readthedocs/rtd_tests/tests/test_config_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mock import MagicMock, PropertyMock, patch

from readthedocs.builds.models import Version
from readthedocs.config import ALL, BuildConfigV1, InvalidConfig, ProjectConfig
from readthedocs.config import ALL, BuildConfigV1, InvalidConfig
from readthedocs.config.tests.utils import apply_fs
from readthedocs.doc_builder.config import load_yaml_config
from readthedocs.doc_builder.environments import LocalBuildEnvironment
Expand All @@ -27,9 +27,7 @@ def create_load(config=None):
"""
Mock out the function of the build load function.
This will create a ProjectConfig list of BuildConfigV1 objects and validate
them. The default load function iterates over files and builds up a list of
objects. Instead of mocking all of this, just mock the end result.
This will create a BuildConfigV1 object and validate it.
"""
if config is None:
config = {}
Expand All @@ -41,14 +39,11 @@ def inner(path=None, env_config=None):
}
if env_config is not None:
env_config_defaults.update(env_config)
yaml_config = ProjectConfig([
BuildConfigV1(
env_config_defaults,
config,
source_file='readthedocs.yml',
source_position=0,
),
])
yaml_config = BuildConfigV1(
env_config_defaults,
config,
source_file='readthedocs.yml',
)
yaml_config.validate()
return yaml_config

Expand Down

0 comments on commit cc9eab1

Please sign in to comment.