Skip to content

Commit

Permalink
0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Jan 9, 2024
1 parent ef5df93 commit 810cb06
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ This code will be executed
```

# Changelog
#### 0.12 (2024-01-09)
- Error when providing invalid options

#### 0.11 (2024-01-09)
- Updated CI and ruff fixes

Expand Down
2 changes: 1 addition & 1 deletion src/sphinx_exec_code/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.11'
__version__ = '0.12'
8 changes: 8 additions & 0 deletions src/sphinx_exec_code/sphinx_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def from_options(cls, options: Dict[str, Any]) -> 'SphinxSpecBase':
if not val:
val = cls.defaults[name]
opts[name] = val

if left := set(options) - set(cls.aliases):
msg = (
f'Invalid option{"s" if len(left) != 1 else ""}: '
f'{", ".join(sorted(map(str, left)))}! Supported: {", ".join(sorted(map(str, cls.aliases)))}'
)
raise ValueError(msg)

return cls(**opts)

@classmethod
Expand Down
12 changes: 10 additions & 2 deletions tests/test_sphinx_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def test_build_spec_code():


def test_spec_code():
obj = SpecCode.from_options({'linenos': None, 'caption': 'my_header'})
obj = SpecCode.from_options({'linenos': None, 'caption': 'my_header', 'filename': 'filename'})
assert obj.caption == 'my_header'
assert obj.language == 'python'
assert obj.linenos is True
assert obj.hide is False
assert obj.filename == ''
assert obj.filename == 'filename'


def test_spec_output():
Expand All @@ -56,3 +56,11 @@ def test_spec_output():
assert obj.language == 'none'
assert obj.linenos is False
assert obj.hide is True


def test_invalid_options():
with pytest.raises(ValueError) as e:
SpecOutput.from_options({'hide-output': None})

assert str(e.value) == ('Invalid option: hide-output! '
'Supported: caption_output, hide_output, language_output, linenos_output')

0 comments on commit 810cb06

Please sign in to comment.