Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/sample/sample_bad_syntax.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"a": 1,
"b": {
"c": "value",
"d": [2, "string"

}
24 changes: 24 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from collections import OrderedDict
import os

import pytest

from cfbs.utils import (
are_paths_equal,
canonify,
Expand Down Expand Up @@ -71,6 +75,10 @@ def test_read_json():
assert read_json("tests/thisfiledoesntexist.json") is None
assert read_json("tests/thisdirdoesntexist/file.json") is None

with pytest.raises(SystemExit) as exc_info:
read_json("tests/sample/sample_bad_syntax.json")
assert exc_info.value.code == 1


def test_merge_json():
original = {"classes": {"services_autorun": ["any"]}}
Expand Down Expand Up @@ -210,6 +218,14 @@ def test_deduplicate_list():

assert deduplicate_list(l) == [1, 2, 3, 4]

assert deduplicate_list([1, 1, 2, 3]) == [1, 2, 3]
assert deduplicate_list([1, 2, 3, 3]) == [1, 2, 3]
assert deduplicate_list([1, 2, 3]) == [1, 2, 3]

assert deduplicate_list([]) == []
assert deduplicate_list([1]) == [1]
assert deduplicate_list([1, 1, 1, 1, 1, 1, 1]) == [1]


def test_dict_sorted_by_key():
d = {"b": 1, "c": 3, "a": 2}
Expand All @@ -218,6 +234,9 @@ def test_dict_sorted_by_key():

assert dict_sorted_by_key(d) == expected_dict

assert dict_sorted_by_key({}) == OrderedDict([])
assert dict_sorted_by_key({"a": 1}) == OrderedDict([("a", 1)])


def test_dict_diff():
A = {"A": "a", "B": "b", "C": "c"}
Expand Down Expand Up @@ -253,6 +272,11 @@ def test_are_paths_equal():

assert are_paths_equal(path_a, path_b)

assert are_paths_equal(".", os.getcwd())

assert are_paths_equal("a", "b") == False
assert are_paths_equal("a", "") == False


def test_string_sha256():
s = "cfbs/masterfiles/"
Expand Down