Open robin92 opened 2 years ago
Sorry to late reply, I checked your test code. There are no specification in my idea for this case because I didn't suppose.
IMO, I prefer to stop execution if anything unexpected occurs. Although, it may be scope of this package if this behavior causes inconvenient for definition of configuration file.
Note that I confirmed that following test code could pass:
# pytest-compatible file
import pathlib
from dataclasses import dataclass
from yamldataclassconfig import YamlDataClassConfig
def test_loads_empty_file(tmp_path: pathlib.Path):
@dataclass
class Config(YamlDataClassConfig):
pass
cfg_path = tmp_path / 'config.yml'
cfg_path.touch()
+ cfg_path.write_text("{}")
Config().load(cfg_path)
Hmm, is {}
a valid YAML? I supposed that an empty file (touched only) is but dunno about {}
.
This is Flow Style
which is useful to define empty dictionary or sequence:
YAML Ain’t Markup Language (YAML™) revision 1.2.2
Example
Expected result Test finishes without error.
Actual result The following error is reported.
Stack:
It looks like Marchmallow's
Schema.load
expectsdata
parameter to always be a dictionary 1. Loading empty file yieldsNone
which is passed further and results in what can be seen above.If you want I may prepare a fix for this, just confirm that Expected result is really expected and it makes sense to correct that, please.