Skip to content

Commit

Permalink
added documentation for new usage and tests to use those. fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Feb 9, 2015
1 parent 08903c2 commit be813df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ Quickstart

.. code-block:: python
from stl import stl
mesh = stl.StlMesh('some_file.stl')
from stl import mesh
# Using an existing stl file:
mesh = mesh.Mesh.from_file('some_file.stl')
# Or creating a new mesh:
VERTICE_COUNT = 100
data = numpy.zeros(VERTICE_COUNT, dtype=Mesh.dtype)
mesh = mesh.Mesh(data, remove_empty_areas=False)
# The mesh normals (calculated automatically)
mesh.normals
# The mesh vectors
Expand Down
24 changes: 12 additions & 12 deletions tests/stl_corruption.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import struct

from stl import stl
from stl import mesh

_STL_FILE = '''
solid test.stl
Expand All @@ -21,7 +21,7 @@ def test_valid_ascii(tmpdir):
with tmp_file.open('w+') as fh:
fh.write(_STL_FILE)
fh.seek(0)
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)


def test_ascii_with_missing_name(tmpdir):
Expand All @@ -36,7 +36,7 @@ def test_ascii_with_missing_name(tmpdir):
# Join the lines to test files that start with solid without space
fh.write('\n'.join(lines))
fh.seek(0)
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)


def test_incomplete_ascii_file(tmpdir):
Expand All @@ -45,25 +45,25 @@ def test_incomplete_ascii_file(tmpdir):
fh.write('solid some_file.stl')
fh.seek(0)
with pytest.raises(struct.error):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)

with tmp_file.open('w+') as fh:
fh.write(_STL_FILE[:-20])
fh.seek(0)
with pytest.raises(AssertionError):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)

with tmp_file.open('w+') as fh:
fh.write(_STL_FILE[:82])
fh.seek(0)
with pytest.raises(struct.error):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)

with tmp_file.open('w+') as fh:
fh.write(_STL_FILE[:100])
fh.seek(0)
with pytest.raises(AssertionError):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)


def test_corrupt_ascii_file(tmpdir):
Expand All @@ -74,7 +74,7 @@ def test_corrupt_ascii_file(tmpdir):
print >>fh, '####\n' * 100
fh.seek(0)
with pytest.raises(AssertionError):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)

with tmp_file.open('w+') as fh:
fh.write(_STL_FILE)
Expand All @@ -84,7 +84,7 @@ def test_corrupt_ascii_file(tmpdir):
fh.write(struct.pack('@i', 10))
fh.seek(0)
with pytest.raises(AssertionError):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)


def test_corrupt_binary_file(tmpdir):
Expand All @@ -93,20 +93,20 @@ def test_corrupt_binary_file(tmpdir):
fh.write('#########\n' * 8)
fh.write('#\0\0\0')
fh.seek(0)
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)

with tmp_file.open('w+') as fh:
fh.write('#########\n' * 9)
fh.seek(0)
with pytest.raises(AssertionError):
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)

with tmp_file.open('w+') as fh:
fh.write('#########\n' * 8)
fh.write('#\0\0\0')
fh.seek(0)
fh.write('solid test.stl')
fh.seek(0)
stl.StlMesh(str(tmp_file), fh=fh)
mesh.Mesh.from_file(str(tmp_file), fh=fh)


0 comments on commit be813df

Please sign in to comment.