Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Allow explicit default with null value #38

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions readthedocs_build/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ def validate_requirements_file(self):
return None

requirements_file = self.raw_config['requirements_file']
if requirements_file is None:
return None
base_path = os.path.dirname(self.source_file)
with self.catch_validation_error('requirements_file'):
validate_file(requirements_file, base_path)
Expand Down
16 changes: 16 additions & 0 deletions readthedocs_build/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
}


config_with_explicit_defaults = {
'readthedocs.yml': '''
name: docs
type: sphinx
requirements_file: null
'''
}


multiple_config_dir = {
'readthedocs.yml': '''
name: first
Expand Down Expand Up @@ -113,6 +122,13 @@ def test_build_config_has_source_position(tmpdir):
assert second.source_position == 1


def test_build_config_has_explicit_default_null_value(tmpdir):
base = str(apply_fs(tmpdir, config_with_explicit_defaults))
build = load(base, env_config)[0]
assert isinstance(build, BuildConfig)
assert 'requirements_file' not in build


def test_build_config_has_list_with_single_null_value(tmpdir):
base = str(apply_fs(tmpdir, config_with_explicit_empty_list))
build = load(base, env_config)[0]
Expand Down
18 changes: 18 additions & 0 deletions readthedocs_build/config/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ def test_parse_single_config():
assert config[0]['base'] == 'path'


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


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


Copy link
Member

Choose a reason for hiding this comment

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

I think a good addition here would be this test also:

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

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


def test_parse_empty_list():
buf = StringIO(u'base: []')
config = parse(buf)
Expand Down