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
17 changes: 16 additions & 1 deletion readthedocs_build/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .config import PYTHON_INVALID
from .validation import INVALID_BOOL
from .validation import INVALID_CHOICE
from .validation import INVALID_DIRECTORY
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep this line for now, in case we have some side effects from removing a line like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

from .validation import INVALID_PATH
from .validation import INVALID_STRING

Expand All @@ -39,6 +38,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 @@ -103,6 +111,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_config_requires_name():
build = BuildConfig({},
{},
Expand Down
12 changes: 12 additions & 0 deletions readthedocs_build/config/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ 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_multiple_configs_in_one_file():
buf = StringIO(
u'''
Expand Down