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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Hamilton Kibbe <ham@hamiltonkib.be>
from ..cam import CamFile, FileSettings
from .tests import *
def test_filesettings_defaults():
""" Test FileSettings default values
"""
fs = FileSettings()
assert_equal(fs.format, (2, 5))
assert_equal(fs.notation, 'absolute')
assert_equal(fs.zero_suppression, 'trailing')
assert_equal(fs.units, 'inch')
def test_filesettings_dict():
""" Test FileSettings Dict
"""
fs = FileSettings()
assert_equal(fs['format'], (2, 5))
assert_equal(fs['notation'], 'absolute')
assert_equal(fs['zero_suppression'], 'trailing')
assert_equal(fs['units'], 'inch')
def test_filesettings_assign():
""" Test FileSettings attribute assignment
"""
fs = FileSettings()
fs.units = 'test1'
fs.notation = 'test2'
fs.zero_suppression = 'test3'
fs.format = 'test4'
assert_equal(fs.units, 'test1')
assert_equal(fs.notation, 'test2')
assert_equal(fs.zero_suppression, 'test3')
assert_equal(fs.format, 'test4')
def test_filesettings_dict_assign():
""" Test FileSettings dict-style attribute assignment
"""
fs = FileSettings()
fs['units'] = 'metric'
fs['notation'] = 'incremental'
fs['zero_suppression'] = 'leading'
fs['format'] = (1, 2)
assert_equal(fs.units, 'metric')
assert_equal(fs.notation, 'incremental')
assert_equal(fs.zero_suppression, 'leading')
assert_equal(fs.format, (1, 2))
def test_camfile_init():
""" Smoke test CamFile test
"""
cf = CamFile()
def test_camfile_settings():
""" Test CamFile Default Settings
"""
cf = CamFile()
assert_equal(cf.settings, FileSettings())
def test_bounds_override_smoketest():
cf = CamFile()
cf.bounds
def test_zeros():
""" Test zero/zero_suppression interaction
"""
fs = FileSettings()
assert_equal(fs.zero_suppression, 'trailing')
assert_equal(fs.zeros, 'leading')
fs['zero_suppression'] = 'leading'
assert_equal(fs.zero_suppression, 'leading')
assert_equal(fs.zeros, 'trailing')
fs.zero_suppression = 'trailing'
assert_equal(fs.zero_suppression, 'trailing')
assert_equal(fs.zeros, 'leading')
fs['zeros'] = 'trailing'
assert_equal(fs.zeros, 'trailing')
assert_equal(fs.zero_suppression, 'leading')
fs.zeros = 'leading'
assert_equal(fs.zeros, 'leading')
assert_equal(fs.zero_suppression, 'trailing')
fs = FileSettings(zeros='leading')
assert_equal(fs.zeros, 'leading')
assert_equal(fs.zero_suppression, 'trailing')
fs = FileSettings(zero_suppression='leading')
assert_equal(fs.zeros, 'trailing')
assert_equal(fs.zero_suppression, 'leading')
fs = FileSettings(zeros='leading', zero_suppression='trailing')
assert_equal(fs.zeros, 'leading')
assert_equal(fs.zero_suppression, 'trailing')
fs = FileSettings(zeros='trailing', zero_suppression='leading')
assert_equal(fs.zeros, 'trailing')
assert_equal(fs.zero_suppression, 'leading')
def test_filesettings_validation():
""" Test FileSettings constructor argument validation
"""
# absolute-ish is not a valid notation
assert_raises(ValueError, FileSettings, 'absolute-ish',
'inch', None, (2, 5), None)
# degrees kelvin isn't a valid unit for a CAM file
assert_raises(ValueError, FileSettings, 'absolute',
'degrees kelvin', None, (2, 5), None)
assert_raises(ValueError, FileSettings, 'absolute',
'inch', 'leading', (2, 5), 'leading')
# Technnically this should be an error, but Eangle files often do this incorrectly so we
# allow it
#assert_raises(ValueError, FileSettings, 'absolute',
# 'inch', 'following', (2, 5), None)
assert_raises(ValueError, FileSettings, 'absolute',
'inch', None, (2, 5), 'following')
assert_raises(ValueError, FileSettings, 'absolute',
'inch', None, (2, 5, 6), None)
def test_key_validation():
fs = FileSettings()
assert_raises(KeyError, fs.__getitem__, 'octopus')
assert_raises(KeyError, fs.__setitem__, 'octopus', 'do not care')
assert_raises(ValueError, fs.__setitem__, 'notation', 'absolute-ish')
assert_raises(ValueError, fs.__setitem__, 'units', 'degrees kelvin')
assert_raises(ValueError, fs.__setitem__, 'zero_suppression', 'following')
assert_raises(ValueError, fs.__setitem__, 'zeros', 'following')
assert_raises(ValueError, fs.__setitem__, 'format', (2, 5, 6))
|