Coverage for tests / unit / utils / test_file_utils.py: 0%

34 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-20 10:09 -0400

1import os 

2import json 

3import yaml 

4from pathlib import Path 

5from graphqler.utils.file_utils import initialize_file, write_json_to_file, write_dict_to_yaml, read_yaml_to_dict 

6 

7 

8def test_initialize_file(): 

9 file_path = Path("test.txt") 

10 initialize_file(file_path) 

11 assert file_path.exists() 

12 os.remove(file_path) 

13 

14 

15def test_write_json_to_file(): 

16 contents = {"name": "John", "age": 30, "city": "New York"} 

17 output_file = "test.json" 

18 write_json_to_file(contents, output_file) 

19 with open(output_file) as f: 

20 data = json.load(f) 

21 assert data == contents 

22 os.remove(output_file) 

23 

24 

25def test_write_dict_to_yaml(): 

26 contents = {"name": "John", "age": 30, "city": "New York"} 

27 output_file = "test.yaml" 

28 write_dict_to_yaml(contents, output_file) 

29 with open(output_file) as f: 

30 data = yaml.safe_load(f) 

31 assert data == contents 

32 os.remove(output_file) 

33 

34 

35def test_read_yaml_to_dict(): 

36 read_path = Path("test.yaml") 

37 contents = {"name": "John", "age": 30, "city": "New York"} 

38 with open(read_path, "w") as f: 

39 yaml.dump(contents, f) 

40 data = read_yaml_to_dict(read_path) 

41 assert data == contents 

42 os.remove(read_path)