-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate_parser.py
More file actions
58 lines (47 loc) · 2.08 KB
/
template_parser.py
File metadata and controls
58 lines (47 loc) · 2.08 KB
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
"""Main file for devoutils.faker test"""
import unittest
import re
import os
from dateutil import parser
from devoutils.faker import BatchFakeGenerator
from devoutils.faker import TemplateParser
class TestTemplateParser(unittest.TestCase):
"""Main class for tests"""
def __init__(self, *args, **kwargs):
super(TestTemplateParser, self).__init__(*args, **kwargs)
def setUp(self):
os.chdir("{!s}{!s}".format(os.path.dirname(os.path.abspath(__file__)),
os.sep))
def test_simple(self):
with open("./template01") as content_file:
text = content_file.read()
template_parser = TemplateParser(template=text)
result = template_parser.process(text)
self.assertTrue(result == 'test1\ntest2')
def test_with_faker(self):
with open("./template02") as content_file:
text = content_file.read()
template_parser = TemplateParser(template=text)
result = template_parser.process(text)
self.assertTrue(re.match("test\d+", result))
def test_with_faker_from_file(self):
with open("./template03") as content_file:
text = content_file.read()
template_parser = TemplateParser(template=text)
result = template_parser.process(text)
self.assertTrue(re.match("test\d+", result))
def test_with_faker_more_complicated(self):
with open("./template04") as content_file:
text = content_file.read()
start_date = parser.parse("01-01-2018 00:00:00")
end_date = parser.parse("01-01-2018 00:05:00")
template_parser = TemplateParser(template=text)
result = \
template_parser.process(date_generator=
BatchFakeGenerator.date_range(start_date,
end_date,
(1, 10),
50))
self.assertTrue('test' in result)
if __name__ == '__main__':
unittest.main()