Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import print_function
2from builtins import str
3import os
4import unittest
5import shutil
6import unittest
7import pickle
8import yaml
9from fundamentals.utKit import utKit
10from fundamentals import tools
11from os.path import expanduser
12home = expanduser("~")
14packageDirectory = utKit("").get_project_root()
15settingsFile = packageDirectory + "/test_settings.yaml"
16# settingsFile = home + "/.config/soxspipe.recipes/soxspipe.recipes.yaml"
17su = tools(
18 arguments={"settingsFile": settingsFile},
19 docString=__doc__,
20 logLevel="DEBUG",
21 options_first=False,
22 projectName=None,
23 defaultSettingsFile=False
24)
25arguments, settings, log, dbConn = su.setup()
27# SETUP AND TEARDOWN FIXTURE FUNCTIONS FOR THE ENTIRE MODULE
28moduleDirectory = os.path.dirname(__file__)
29utKit = utKit(moduleDirectory)
30log, dbConn, pathToInputDir, pathToOutputDir = utKit.setupModule()
31utKit.tearDownModule()
33try:
34 shutil.rmtree(pathToOutputDir)
35except:
36 pass
37# COPY INPUT TO OUTPUT DIR
38shutil.copytree(pathToInputDir, pathToOutputDir)
40# Recursively create missing directories
41if not os.path.exists(pathToOutputDir):
42 os.makedirs(pathToOutputDir)
44pathToPickleFile = pathToInputDir + "/list-of-dictionaries.p"
46listOfDictionaries = pickle.load(open(pathToPickleFile, "rb"))
48class test_list_of_dictionaries(unittest.TestCase):
50 def test_list_of_dictionaries_function(self):
52 from fundamentals.renderer import list_of_dictionaries
53 dataSet = list_of_dictionaries(
54 log=log,
55 listOfDictionaries=listOfDictionaries
56 )
57 # print(dataSet.table())
58 dataSet.table(filepath=pathToOutputDir + "myData.dat")
59 # print(dataSet.csv())
60 dataSet.csv(filepath=pathToOutputDir + "myData.csv")
61 # print(dataSet.mysql(tableName="TNS"))
62 dataSet.mysql(tableName="TNS",
63 filepath=pathToOutputDir + "myData.mysql")
65 # print(dataSet.json())
66 dataSet.json(filepath=pathToOutputDir + "myData.json")
67 # print(dataSet.yaml())
68 dataSet.yaml(filepath=pathToOutputDir + "myData.yaml")
69 # print(dataSet.markdown())
70 dataSet.markdown(filepath=pathToOutputDir + "myData.md")
72 def test_list_of_dictionaries_function_02(self):
74 dataList = [
75 {
76 "owner": "daisy",
77 "pet": "dog",
78 "address": "belfast, uk"
79 },
80 {
81 "owner": "john",
82 "pet": "snake",
83 "address": "the moon"
84 },
85 {
86 "owner": "susan",
87 "pet": "crocodile",
88 "address": "larne"
89 }
91 ]
93 from fundamentals.renderer import list_of_dictionaries
94 dataSet = list_of_dictionaries(
95 log=log,
96 listOfDictionaries=dataList
97 )
98 # print(dataSet.table())
99 dataSet.table(filepath=pathToOutputDir + "myData.dat")
100 # print(dataSet.csv())
101 dataSet.csv(filepath=pathToOutputDir + "myData.csv")
102 # print(dataSet.mysql(tableName="TNS"))
103 dataSet.mysql(tableName="TNS",
104 filepath=pathToOutputDir + "myData.mysql")
105 # print(dataSet.json())
106 dataSet.json(filepath=pathToOutputDir + "myData.json")
107 # print(dataSet.yaml())
108 dataSet.yaml(filepath=pathToOutputDir + "myData.yaml")
109 # print(dataSet.markdown())
110 dataSet.markdown(filepath=pathToOutputDir + "myData.md")
112 def test_list_of_dictionaries_function_exception(self):
114 from fundamentals.renderer import list_of_dictionaries
115 try:
116 this = list_of_dictionaries(
117 log=log,
118 listOfDictionaries=listOfDictionaries,
119 fakeKey="break the code"
120 )
121 this.get()
122 assert False
123 except Exception as e:
124 assert True
125 # print(str(e))
127 # x-print-testpage-for-pessto-marshall-web-object
129 # x-class-to-test-named-worker-function