Make pcb-tools pytest pass without warnings
This commit is contained in:
parent
83e498b891
commit
4bb9981122
10 changed files with 22 additions and 19 deletions
|
|
@ -36,7 +36,7 @@ def read(filename):
|
|||
CncFile object representing the file, either GerberFile, ExcellonFile,
|
||||
or IPCNetlist. Returns None if file is not of the proper type.
|
||||
"""
|
||||
with open(filename, 'rU') as f:
|
||||
with open(filename, 'r') as f:
|
||||
data = f.read()
|
||||
return loads(data, filename)
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ def read(filename):
|
|||
|
||||
"""
|
||||
# File object should use settings from source file by default.
|
||||
with open(filename, 'rU') as f:
|
||||
with open(filename, 'r') as f:
|
||||
data = f.read()
|
||||
settings = FileSettings(**detect_excellon_format(data))
|
||||
return ExcellonParser(settings).parse(filename)
|
||||
|
|
@ -426,7 +426,7 @@ class ExcellonParser(object):
|
|||
return len(self.hits)
|
||||
|
||||
def parse(self, filename):
|
||||
with open(filename, 'rU') as f:
|
||||
with open(filename, 'r') as f:
|
||||
data = f.read()
|
||||
return self.parse_raw(data, filename)
|
||||
|
||||
|
|
@ -818,7 +818,7 @@ def detect_excellon_format(data=None, filename=None):
|
|||
if data is None and filename is None:
|
||||
raise ValueError('Either data or filename arguments must be provided')
|
||||
if data is None:
|
||||
with open(filename, 'rU') as f:
|
||||
with open(filename, 'r') as f:
|
||||
data = f.read()
|
||||
|
||||
# Check for obvious clues:
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ class IPCNetlistParser(object):
|
|||
return FileSettings(units=self.units, angle_units=self.angle_units)
|
||||
|
||||
def parse(self, filename):
|
||||
with open(filename, 'rU') as f:
|
||||
with open(filename, 'r') as f:
|
||||
data = f.read()
|
||||
return self.parse_raw(data, filename)
|
||||
|
||||
|
|
@ -382,8 +382,8 @@ class IPC356_Outline(object):
|
|||
coord_strings = line.strip().split()[1:]
|
||||
for coord in coord_strings:
|
||||
coord_dict = _COORD.match(coord).groupdict()
|
||||
x = int(coord_dict['x']) if coord_dict['x'] is not '' else x
|
||||
y = int(coord_dict['y']) if coord_dict['y'] is not '' else y
|
||||
x = int(coord_dict['x']) if coord_dict['x'] != '' else x
|
||||
y = int(coord_dict['y']) if coord_dict['y'] != '' else y
|
||||
points.append((x * scale, y * scale))
|
||||
return cls(type, points)
|
||||
|
||||
|
|
@ -412,9 +412,9 @@ class IPC356_Conductor(object):
|
|||
x = 0
|
||||
y = 0
|
||||
x = int(aperture_dict['x']) * \
|
||||
scale if aperture_dict['x'] is not '' else None
|
||||
scale if aperture_dict['x'] != '' else None
|
||||
y = int(aperture_dict['y']) * \
|
||||
scale if aperture_dict['y'] is not '' else None
|
||||
scale if aperture_dict['y'] != '' else None
|
||||
aperture = (x, y)
|
||||
|
||||
# Parse out conductor shapes
|
||||
|
|
@ -428,8 +428,8 @@ class IPC356_Conductor(object):
|
|||
coords = rshape.split()
|
||||
for coord in coords:
|
||||
coord_dict = _COORD.match(coord).groupdict()
|
||||
x = int(coord_dict['x']) if coord_dict['x'] is not '' else x
|
||||
y = int(coord_dict['y']) if coord_dict['y'] is not '' else y
|
||||
x = int(coord_dict['x']) if coord_dict['x'] != '' else x
|
||||
y = int(coord_dict['y']) if coord_dict['y'] != '' else y
|
||||
shape.append((x * scale, y * scale))
|
||||
shapes.append(tuple(shape))
|
||||
return cls(net_name, layer, aperture, tuple(shapes))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from . import excellon
|
|||
from . import dxf
|
||||
|
||||
def read(filename, format=None):
|
||||
with open(filename, 'rU') as f:
|
||||
with open(filename, 'r') as f:
|
||||
data = f.read()
|
||||
return loads(data, filename, format=format)
|
||||
|
||||
|
|
|
|||
|
|
@ -1687,6 +1687,7 @@ class Slot(Primitive):
|
|||
class TestRecord(Primitive):
|
||||
""" Netlist Test record
|
||||
"""
|
||||
__test__ = False # This is not a PyTest unit test.
|
||||
|
||||
def __init__(self, position, net_name, layer, **kwargs):
|
||||
super(TestRecord, self).__init__(**kwargs)
|
||||
|
|
|
|||
|
|
@ -136,8 +136,10 @@ class GerberCairoContext(GerberContext):
|
|||
is_svg = os.path.splitext(filename.lower())[1] == '.svg'
|
||||
except:
|
||||
is_svg = False
|
||||
|
||||
if verbose:
|
||||
print('[Render]: Writing image to {}'.format(filename))
|
||||
|
||||
if is_svg:
|
||||
self.surface.finish()
|
||||
self.surface_buffer.flush()
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ class GerberParser(object):
|
|||
|
||||
def parse(self, filename):
|
||||
self.filename = filename
|
||||
with open(filename, "rU") as fp:
|
||||
with open(filename, "r") as fp:
|
||||
data = fp.read()
|
||||
return self.parse_raw(data, filename)
|
||||
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ def _test_render(gerber_path, png_expected_path, create_output_path=None):
|
|||
ctx = GerberCairoContext()
|
||||
gerber.render(ctx)
|
||||
|
||||
actual_bytes = ctx.dump(None)
|
||||
actual_bytes = ctx.dump_str()
|
||||
|
||||
# If we want to write the file bytes, do it now. This happens
|
||||
if create_output_path:
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ def test_file_type_detection():
|
|||
|
||||
|
||||
def test_load_from_string():
|
||||
with open(NCDRILL_FILE, "rU") as f:
|
||||
with open(NCDRILL_FILE, "r") as f:
|
||||
ncdrill = loads(f.read())
|
||||
with open(TOP_COPPER_FILE, "rU") as f:
|
||||
with open(TOP_COPPER_FILE, "r") as f:
|
||||
top_copper = loads(f.read())
|
||||
assert isinstance(ncdrill, ExcellonFile)
|
||||
assert isinstance(top_copper, GerberFile)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ NCDRILL_FILE = os.path.join(os.path.dirname(__file__), "resources/ncdrill.DRD")
|
|||
def test_format_detection():
|
||||
""" Test file type detection
|
||||
"""
|
||||
with open(NCDRILL_FILE, "rU") as f:
|
||||
with open(NCDRILL_FILE, "r") as f:
|
||||
data = f.read()
|
||||
settings = detect_excellon_format(data)
|
||||
assert settings["format"] == (2, 4)
|
||||
|
|
@ -36,9 +36,9 @@ def test_read():
|
|||
def test_write():
|
||||
ncdrill = read(NCDRILL_FILE)
|
||||
ncdrill.write("test.ncd")
|
||||
with open(NCDRILL_FILE, "rU") as src:
|
||||
with open(NCDRILL_FILE, "r") as src:
|
||||
srclines = src.readlines()
|
||||
with open("test.ncd", "rU") as res:
|
||||
with open("test.ncd", "r") as res:
|
||||
for idx, line in enumerate(res):
|
||||
assert line.strip() == srclines[idx].strip()
|
||||
os.remove("test.ncd")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue