Skip to content

Commit 8492e6a

Browse files
authored
Merge pull request #238 from jakub-nt/CFE-4538
CFE-4538: Add more unit test edge cases
2 parents 952f6a5 + 16578d1 commit 8492e6a

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"a": 1,
3+
"b": {
4+
"c": "value",
5+
"d": [2, "string"
6+
7+
}

tests/test_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from collections import OrderedDict
2+
import os
3+
4+
import pytest
5+
26
from cfbs.utils import (
37
are_paths_equal,
48
canonify,
@@ -71,6 +75,10 @@ def test_read_json():
7175
assert read_json("tests/thisfiledoesntexist.json") is None
7276
assert read_json("tests/thisdirdoesntexist/file.json") is None
7377

78+
with pytest.raises(SystemExit) as exc_info:
79+
read_json("tests/sample/sample_bad_syntax.json")
80+
assert exc_info.value.code == 1
81+
7482

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

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

221+
assert deduplicate_list([1, 1, 2, 3]) == [1, 2, 3]
222+
assert deduplicate_list([1, 2, 3, 3]) == [1, 2, 3]
223+
assert deduplicate_list([1, 2, 3]) == [1, 2, 3]
224+
225+
assert deduplicate_list([]) == []
226+
assert deduplicate_list([1]) == [1]
227+
assert deduplicate_list([1, 1, 1, 1, 1, 1, 1]) == [1]
228+
213229

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

219235
assert dict_sorted_by_key(d) == expected_dict
220236

237+
assert dict_sorted_by_key({}) == OrderedDict([])
238+
assert dict_sorted_by_key({"a": 1}) == OrderedDict([("a", 1)])
239+
221240

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

254273
assert are_paths_equal(path_a, path_b)
255274

275+
assert are_paths_equal(".", os.getcwd())
276+
277+
assert are_paths_equal("a", "b") == False
278+
assert are_paths_equal("a", "") == False
279+
256280

257281
def test_string_sha256():
258282
s = "cfbs/masterfiles/"

0 commit comments

Comments
 (0)