Skip to content

Commit

Permalink
Merge 68972ec into 837a0a9
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar committed Feb 16, 2018
2 parents 837a0a9 + 68972ec commit 656e1a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions git_json_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def decode(repo, tree_id):
return []
elif b'.object' in tree:
return {}

raise TypeError('Unknown tree type.')

if all((isinstance(key[0], key_types) for key in items)):
Expand Down
30 changes: 29 additions & 1 deletion test_git_json_tree.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Test Git-JSON-Tree library."""

import json
from string import printable

import hypothesis.strategies as st
import pytest
from click.testing import CliRunner
from dulwich.repo import Repo
from hypothesis import assume, given, settings

from git_json_tree import decode, encode
from git_json_tree import cli, decode, encode


@pytest.fixture()
Expand All @@ -16,6 +18,12 @@ def repo(tmpdir):
yield Repo.init_bare(str(tmpdir))


@pytest.fixture()
def runner(repo):
"""Define a click runner."""
return CliRunner()


def json_data():
"""Generate JSON data."""
return st.recursive(
Expand Down Expand Up @@ -43,3 +51,23 @@ def test_encode_decode(data, repo):
"""Test (d)encoding."""
assume(isinstance(data, (dict, list)))
assert decode(repo, encode(repo, data)) == data


@given(data=json_data())
@settings(max_examples=100, deadline=10000)
def test_cli_encoder(data, runner):
"""Test cli encoder."""
assume(isinstance(data, (dict, list)))
encoded = runner.invoke(cli, ['encode'], input=json.dumps(data))
decoded = runner.invoke(cli, ['decode', encoded.output.strip()])
assert json.loads(decoded.output) == data


@given(data=json_data())
@settings(max_examples=100, deadline=10000)
def test_smudge_clean(data, runner):
"""Test Git integration."""
assume(isinstance(data, (dict, list)))
cleaned = runner.invoke(cli, ['clean'], input=json.dumps(data))
smudged = runner.invoke(cli, ['smudge'], input=cleaned.output)
assert json.loads(smudged.output) == data

0 comments on commit 656e1a4

Please sign in to comment.