11from collections import OrderedDict
2+ import os
3+
4+ import pytest
5+
26from 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
7583def 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
214230def 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
222241def 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
257281def test_string_sha256 ():
258282 s = "cfbs/masterfiles/"
0 commit comments