Skip to content

Commit

Permalink
Add tests for deserializing empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jan 14, 2019
1 parent a9d9c49 commit 3ed7a02
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions datafiles/tests/test_formats.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
# pylint: disable=unused-variable

from pathlib import Path

import pytest

from datafiles import formats


def describe_deserialize():
def it_rejects_unknown_extensions(expect):
@pytest.fixture
def path(tmp_path):
path = tmp_path / "sample"
path.write_text("")
return path

def with_empty_yaml_file(expect, path):
data = formats.deserialize(path, '.yaml')
expect(data) == {}

def with_empty_json_file(expect, path):
path.write_text("{}")
data = formats.deserialize(path, '.json')
expect(data) == {}

def with_empty_toml_file(expect, path):
data = formats.deserialize(path, '.toml')
expect(data) == {}

def with_unknown_extension(expect, path):
with expect.raises(ValueError):
formats.deserialize(Path(), '.xyz')
formats.deserialize(path, '.xyz')

0 comments on commit 3ed7a02

Please sign in to comment.