Skip to content

Commit cc9eab1

Browse files
committed
Fix tests
1 parent 8de5432 commit cc9eab1

File tree

3 files changed

+24
-86
lines changed

3 files changed

+24
-86
lines changed

readthedocs/config/tests/test_config.py

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
ConfigError,
1818
ConfigOptionNotSupportedError,
1919
InvalidConfig,
20-
ProjectConfig,
2120
load,
2221
)
2322
from readthedocs.config.config import (
@@ -81,13 +80,11 @@
8180
}
8281

8382

84-
def get_build_config(config, env_config=None, source_file='readthedocs.yml',
85-
source_position=0):
83+
def get_build_config(config, env_config=None, source_file='readthedocs.yml'):
8684
return BuildConfigV1(
8785
env_config or {},
8886
config,
8987
source_file=source_file,
90-
source_position=source_position,
9188
)
9289

9390

@@ -131,10 +128,7 @@ def test_load_empty_config_file(tmpdir):
131128
def test_minimal_config(tmpdir):
132129
apply_fs(tmpdir, minimal_config_dir)
133130
base = str(tmpdir)
134-
config = load(base, env_config)
135-
assert isinstance(config, ProjectConfig)
136-
assert len(config) == 1
137-
build = config[0]
131+
build = load(base, env_config)
138132
assert isinstance(build, BuildConfigV1)
139133

140134

@@ -145,10 +139,7 @@ def test_load_version1(tmpdir):
145139
''')
146140
})
147141
base = str(tmpdir)
148-
config = load(base, get_env_config({'allow_v2': True}))
149-
assert isinstance(config, ProjectConfig)
150-
assert len(config) == 1
151-
build = config[0]
142+
build = load(base, get_env_config({'allow_v2': True}))
152143
assert isinstance(build, BuildConfigV1)
153144

154145

@@ -159,10 +150,7 @@ def test_load_version2(tmpdir):
159150
''')
160151
})
161152
base = str(tmpdir)
162-
config = load(base, get_env_config({'allow_v2': True}))
163-
assert isinstance(config, ProjectConfig)
164-
assert len(config) == 1
165-
build = config[0]
153+
build = load(base, get_env_config({'allow_v2': True}))
166154
assert isinstance(build, BuildConfigV2)
167155

168156

@@ -183,31 +171,18 @@ def test_yaml_extension(tmpdir):
183171
apply_fs(tmpdir, yaml_extension_config_dir)
184172
base = str(tmpdir)
185173
config = load(base, env_config)
186-
assert len(config) == 1
174+
assert isinstance(config, BuildConfigV1)
187175

188176

189177
def test_build_config_has_source_file(tmpdir):
190178
base = str(apply_fs(tmpdir, minimal_config_dir))
191-
build = load(base, env_config)[0]
179+
build = load(base, env_config)
192180
assert build.source_file == os.path.join(base, 'readthedocs.yml')
193-
assert build.source_position == 0
194-
195-
196-
def test_build_config_has_source_position(tmpdir):
197-
base = str(apply_fs(tmpdir, multiple_config_dir))
198-
builds = load(base, env_config)
199-
assert len(builds) == 2
200-
first, second = filter(
201-
lambda b: not b.source_file.endswith('nested/readthedocs.yml'),
202-
builds,
203-
)
204-
assert first.source_position == 0
205-
assert second.source_position == 1
206181

207182

208183
def test_build_config_has_list_with_single_empty_value(tmpdir):
209184
base = str(apply_fs(tmpdir, config_with_explicit_empty_list))
210-
build = load(base, env_config)[0]
185+
build = load(base, env_config)
211186
assert isinstance(build, BuildConfigV1)
212187
assert build.formats == []
213188

@@ -217,7 +192,6 @@ def test_config_requires_name():
217192
{'output_base': ''},
218193
{},
219194
source_file='readthedocs.yml',
220-
source_position=0,
221195
)
222196
with raises(InvalidConfig) as excinfo:
223197
build.validate()
@@ -230,7 +204,6 @@ def test_build_requires_valid_name():
230204
{'output_base': ''},
231205
{'name': 'with/slashes'},
232206
source_file='readthedocs.yml',
233-
source_position=0,
234207
)
235208
with raises(InvalidConfig) as excinfo:
236209
build.validate()
@@ -554,7 +527,6 @@ def test_valid_build_config():
554527
env_config,
555528
minimal_config,
556529
source_file='readthedocs.yml',
557-
source_position=0,
558530
)
559531
build.validate()
560532
assert build.name == 'docs'
@@ -576,7 +548,6 @@ def it_validates_to_abspath(tmpdir):
576548
get_env_config(),
577549
{'base': '../docs'},
578550
source_file=source_file,
579-
source_position=0,
580551
)
581552
build.validate()
582553
assert build.base == str(tmpdir.join('docs'))
@@ -597,7 +568,6 @@ def it_fails_if_base_is_not_a_string(tmpdir):
597568
get_env_config(),
598569
{'base': 1},
599570
source_file=str(tmpdir.join('readthedocs.yml')),
600-
source_position=0,
601571
)
602572
with raises(InvalidConfig) as excinfo:
603573
build.validate()
@@ -610,7 +580,6 @@ def it_fails_if_base_does_not_exist(tmpdir):
610580
get_env_config(),
611581
{'base': 'docs'},
612582
source_file=str(tmpdir.join('readthedocs.yml')),
613-
source_position=0,
614583
)
615584
with raises(InvalidConfig) as excinfo:
616585
build.validate()
@@ -626,7 +595,6 @@ def it_fails_if_build_is_invalid_option(tmpdir):
626595
get_env_config(),
627596
{'build': {'image': 3.0}},
628597
source_file=str(tmpdir.join('readthedocs.yml')),
629-
source_position=0,
630598
)
631599
with raises(InvalidConfig) as excinfo:
632600
build.validate()
@@ -642,7 +610,6 @@ def it_fails_on_python_validation(tmpdir):
642610
'python': {'version': '3.3'},
643611
},
644612
source_file=str(tmpdir.join('readthedocs.yml')),
645-
source_position=0,
646613
)
647614
build.validate_build()
648615
with raises(InvalidConfig) as excinfo:
@@ -659,7 +626,6 @@ def it_works_on_python_validation(tmpdir):
659626
'python': {'version': '3.3'},
660627
},
661628
source_file=str(tmpdir.join('readthedocs.yml')),
662-
source_position=0,
663629
)
664630
build.validate_build()
665631
build.validate_python()
@@ -670,7 +636,6 @@ def it_works(tmpdir):
670636
get_env_config(),
671637
{'build': {'image': 'latest'}},
672638
source_file=str(tmpdir.join('readthedocs.yml')),
673-
source_position=0,
674639
)
675640
build.validate()
676641
assert build.build.image == 'readthedocs/build:latest'
@@ -681,7 +646,6 @@ def default(tmpdir):
681646
get_env_config(),
682647
{},
683648
source_file=str(tmpdir.join('readthedocs.yml')),
684-
source_position=0,
685649
)
686650
build.validate()
687651
assert build.build.image == 'readthedocs/build:2.0'
@@ -697,7 +661,6 @@ def it_priorities_image_from_env_config(tmpdir, image):
697661
get_env_config({'defaults': defaults}),
698662
{'build': {'image': 'latest'}},
699663
source_file=str(tmpdir.join('readthedocs.yml')),
700-
source_position=0,
701664
)
702665
build.validate()
703666
assert build.build.image == image
@@ -787,7 +750,6 @@ def test_build_validate_calls_all_subvalidators(tmpdir):
787750
{},
788751
{},
789752
source_file=str(tmpdir.join('readthedocs.yml')),
790-
source_position=0,
791753
)
792754
with patch.multiple(
793755
BuildConfigV1,
@@ -803,20 +765,6 @@ def test_build_validate_calls_all_subvalidators(tmpdir):
803765
BuildConfigV1.validate_output_base.assert_called_with()
804766

805767

806-
def test_validate_project_config():
807-
with patch.object(BuildConfigV1, 'validate') as build_validate:
808-
project = ProjectConfig([
809-
BuildConfigV1(
810-
env_config,
811-
minimal_config,
812-
source_file='readthedocs.yml',
813-
source_position=0,
814-
),
815-
])
816-
project.validate()
817-
assert build_validate.call_count == 1
818-
819-
820768
def test_load_calls_validate(tmpdir):
821769
apply_fs(tmpdir, minimal_config_dir)
822770
base = str(tmpdir)
@@ -844,12 +792,11 @@ def test_config_filenames_regex(correct_config_filename):
844792
class TestBuildConfigV2(object):
845793

846794
def get_build_config(self, config, env_config=None,
847-
source_file='readthedocs.yml', source_position=0):
795+
source_file='readthedocs.yml'):
848796
return BuildConfigV2(
849797
env_config or {},
850798
config,
851799
source_file=source_file,
852-
source_position=source_position,
853800
)
854801

855802
def test_version(self):

readthedocs/config/tests/test_parser.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,35 @@ def test_parse_bad_type():
2828
def test_parse_single_config():
2929
buf = StringIO(u'base: path')
3030
config = parse(buf)
31-
assert isinstance(config, list)
32-
assert len(config) == 1
33-
assert config[0]['base'] == 'path'
31+
assert isinstance(config, dict)
32+
assert config['base'] == 'path'
3433

3534

3635
def test_parse_null_value():
3736
buf = StringIO(u'base: null')
3837
config = parse(buf)
39-
assert config[0]['base'] is None
38+
assert config['base'] is None
4039

4140

4241
def test_parse_empty_value():
4342
buf = StringIO(u'base:')
4443
config = parse(buf)
45-
assert config[0]['base'] is None
44+
assert config['base'] is None
4645

4746

4847
def test_parse_empty_string_value():
4948
buf = StringIO(u'base: ""')
5049
config = parse(buf)
51-
assert config[0]['base'] == ''
50+
assert config['base'] == ''
5251

5352

5453
def test_parse_empty_list():
5554
buf = StringIO(u'base: []')
5655
config = parse(buf)
57-
assert config[0]['base'] == []
56+
assert config['base'] == []
5857

5958

60-
def test_parse_multiple_configs_in_one_file():
59+
def test_do_not_parse_multiple_configs_in_one_file():
6160
buf = StringIO(
6261
u'''
6362
base: path
@@ -67,8 +66,5 @@ def test_parse_multiple_configs_in_one_file():
6766
nested:
6867
works: true
6968
''')
70-
configs = parse(buf)
71-
assert isinstance(configs, list)
72-
assert len(configs) == 2
73-
assert configs[0]['base'] == 'path'
74-
assert configs[1]['nested'] == {'works': True}
69+
with raises(ParseError):
70+
parse(buf)

readthedocs/rtd_tests/tests/test_config_integration.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from mock import MagicMock, PropertyMock, patch
1414

1515
from readthedocs.builds.models import Version
16-
from readthedocs.config import ALL, BuildConfigV1, InvalidConfig, ProjectConfig
16+
from readthedocs.config import ALL, BuildConfigV1, InvalidConfig
1717
from readthedocs.config.tests.utils import apply_fs
1818
from readthedocs.doc_builder.config import load_yaml_config
1919
from readthedocs.doc_builder.environments import LocalBuildEnvironment
@@ -27,9 +27,7 @@ def create_load(config=None):
2727
"""
2828
Mock out the function of the build load function.
2929
30-
This will create a ProjectConfig list of BuildConfigV1 objects and validate
31-
them. The default load function iterates over files and builds up a list of
32-
objects. Instead of mocking all of this, just mock the end result.
30+
This will create a BuildConfigV1 object and validate it.
3331
"""
3432
if config is None:
3533
config = {}
@@ -41,14 +39,11 @@ def inner(path=None, env_config=None):
4139
}
4240
if env_config is not None:
4341
env_config_defaults.update(env_config)
44-
yaml_config = ProjectConfig([
45-
BuildConfigV1(
46-
env_config_defaults,
47-
config,
48-
source_file='readthedocs.yml',
49-
source_position=0,
50-
),
51-
])
42+
yaml_config = BuildConfigV1(
43+
env_config_defaults,
44+
config,
45+
source_file='readthedocs.yml',
46+
)
5247
yaml_config.validate()
5348
return yaml_config
5449

0 commit comments

Comments
 (0)