From dd63b169f177389602e17bc6ced53bd0f1ba0de3 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 10 Oct 2015 16:51:21 -0400 Subject: Allow files to be read from strings per #37 Adds a loads() method to the top level module which generates a GerberFile or ExcellonFile from a string --- gerber/tests/test_common.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gerber/tests/test_common.py') diff --git a/gerber/tests/test_common.py b/gerber/tests/test_common.py index 76e3991..0ba4b68 100644 --- a/gerber/tests/test_common.py +++ b/gerber/tests/test_common.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe -from ..common import read +from ..common import read, loads from ..excellon import ExcellonFile from ..rs274x import GerberFile from .tests import * @@ -23,9 +23,20 @@ def test_file_type_detection(): assert_true(isinstance(ncdrill, ExcellonFile)) assert_true(isinstance(top_copper, GerberFile)) + +def test_load_from_string(): + with open(NCDRILL_FILE, 'r') as f: + ncdrill = loads(f.read()) + with open(TOP_COPPER_FILE, 'r') as f: + top_copper = loads(f.read()) + assert_true(isinstance(ncdrill, ExcellonFile)) + assert_true(isinstance(top_copper, GerberFile)) + + def test_file_type_validation(): """ Test file format validation """ assert_raises(TypeError, read, 'LICENSE') + -- cgit