-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
74 lines (69 loc) · 1.69 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pytest
import json
import unittest
import os
from main import parse_json
def test_conf1():
output = """C configuration example
(def comment "configuration example")
(def player table(
name => "Player1",
health => "100",
level => "1",
inventory => table(
weapon => "sword",
items => "potion"
)
))"""
file = "config1.json"
with open(file, 'r', encoding='utf-8') as f:
json_data = json.load(f)
assert parse_json(json_data) == output
def test_conf2():
output = """C constant calculation
(def comment "constant calculation")
(def constant_1 123)
(def constant_2 "hello")
(def constant_3 "hello")
(def constant_4 123)"""
file = "config2.json"
with open(file, 'r', encoding='utf-8') as f:
json_data = json.load(f)
assert parse_json(json_data) == output
def test_conf3():
output = """(def name "Городская библиотека")
(def location "Москва, Россия")
(def book1 table(
title => "Война и мир",
author => "Лев Толстой",
published_year => 1869,
genre => "роман-эпопея",
availability => table(
available_copies => 3,
total_copies => 10
)
))
(def book2 table(
title => "1984",
author => "Джордж Оруэлл",
published_year => 1949,
genre => "роман",
availability => table(
available_copies => 0,
total_copies => 5
)
))
(def book3 table(
title => "Мастер и Маргарита",
author => "Михаил Булгаков",
published_year => 1967,
genre => "фантастика",
availability => table(
available_copies => 2,
total_copies => 7
)
))"""
file = "config3.json"
with open(file, 'r', encoding='utf-8') as f:
json_data = json.load(f)
assert parse_json(json_data) == output