forked from niklasvincent/ipplan2sqlite
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBaseTestCase.py
More file actions
68 lines (54 loc) · 1.76 KB
/
Copy pathBaseTestCase.py
File metadata and controls
68 lines (54 loc) · 1.76 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
59
60
61
62
63
64
65
66
67
68
import json
import logging
import os
import sqlite3
import sys
import unittest
import yaml
from collections import namedtuple
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../lib'))
sys.path.insert(1, path)
from lib import tables
def namedtuple_factory(cursor, row):
fields = [col[0] for col in cursor.description]
Row = namedtuple("Row", fields)
return Row(*row)
class BaseTestCase(object):
def _query(self, q):
return self.c.execute(q).fetchall()
def _load(self, f):
f = os.path.abspath(os.path.join(os.path.dirname(__file__), f))
with open(f, 'r') as f:
lines = f.readlines()
return lines
def _load_JSON(self, f):
f = os.path.abspath(os.path.join(os.path.dirname(__file__), f))
with open(f, 'r') as f:
data = json.load(f)
return data
def _load_YAML(self, f):
f = os.path.abspath(os.path.join(os.path.dirname(__file__), f))
with open(f, 'r') as f:
data = yaml.safe_load(f.read())
return data
def setUp(self):
self.conn = sqlite3.connect(':memory:')
self.conn.row_factory = namedtuple_factory
self.c = self.conn.cursor()
tables.create(self.conn)
logging.info('Setting up %s', self._testMethodName)
def tearDown(self):
self.conn.close()
self.c = None
@staticmethod
def main():
# Set up logging
root = logging.getLogger()
ch = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'%(asctime)s - ipplan2sqlite - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
ch.setLevel(logging.DEBUG)
root.setLevel(logging.DEBUG)
unittest.main()