-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_save_restore_layout.py
111 lines (85 loc) · 5.1 KB
/
test_save_restore_layout.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import pcbnew
import logging
import sys
import os
from save_restore_layout import SaveLayout
from save_restore_layout import RestoreLayout
class TestSave(unittest.TestCase):
def test_save_shallow(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'L401'
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 1
data_file = os.path.join(prj_dir, 'source_layout_test_shallow.pckl')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, True)
def test_save_deep(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
source_file = os.path.join(prj_dir, 'save_restore_source_project.kicad_pcb')
board = pcbnew.LoadBoard(source_file)
src_anchor_fp_ref = 'L401'
save_layout = SaveLayout(board, src_anchor_fp_ref)
# get the level from user
level = 0
data_file = os.path.join(prj_dir, 'source_layout_test_deep.pckl')
save_layout.save_layout(save_layout.src_anchor_fp.sheet_id[0:level + 1], data_file,
True, True, True, True, True)
def test_restore_shallow_different_level(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'source_layout_test_shallow.pckl')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'L201'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "group")
restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_shallow_different.kicad_pcb"), board)
def test_restore_shallow_same_level(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'source_layout_test_shallow.pckl')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'L401'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "group")
restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_shallow_same.kicad_pcb"), board)
def test_restore_deep(self):
prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreDestinationProject/")))
src_prj_dir = os.path.normpath(os.path.dirname(os.path.join(os.path.dirname(os.path.realpath(__file__)),
"SaveRestoreSourceProject/")))
data_file = os.path.join(src_prj_dir, 'source_layout_test_deep.pckl')
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'L401'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "group")
restore_layout.restore_layout(data_file)
saved = pcbnew.SaveBoard(destination_file.replace(".kicad_pcb", "_deep.kicad_pcb"), board)
if __name__ == "__main__":
file_handler = logging.FileHandler(filename='save_restore_layout.log', mode='w')
stdout_handler = logging.StreamHandler(sys.stdout)
handlers = [file_handler, stdout_handler]
logging_level = logging.INFO
logging.basicConfig(level=logging_level,
format='%(asctime)s %(name)s %(lineno)d:%(message)s',
datefmt='%m-%d %H:%M:%S',
handlers=handlers
)
logger = logging.getLogger(__name__)
logger.info("Plugin executed on: " + repr(sys.platform))
logger.info("Plugin executed with python version: " + repr(sys.version))
logger.info("KiCad build version: " + str(pcbnew.GetBuildVersion()))
unittest.main()