Skip to content

Commit

Permalink
Merge a7382a1 into 85c6af1
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Nov 9, 2018
2 parents 85c6af1 + a7382a1 commit 24e7d85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
26 changes: 26 additions & 0 deletions tests/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import unittest
import itertools
import subprocess
import contextlib
import threading
import http.server
import socketserver

import numpy as np

Expand Down Expand Up @@ -113,6 +117,28 @@ def get_mesh(file_name, *args, **kwargs):
return list(meshes)


@contextlib.contextmanager
def serve_meshes():
"""
This context manager serves meshes over HTTP at some available port
"""
class _ServerThread(threading.Thread):
def run(self):
os.chdir(dir_models)
Handler = http.server.SimpleHTTPRequestHandler
self.httpd = socketserver.TCPServer(('', 0), Handler)
_, self.port = self.httpd.server_address
self.httpd.serve_forever()

t = _ServerThread()
t.daemon = False
t.start()
time.sleep(0.2)
yield 'http://localhost:{}'.format(t.port)
t.httpd.shutdown()
t.join()


def get_meshes(count=np.inf,
raise_error=False,
only_watertight=True):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_loaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def test_remote(self):
"""
Try loading a remote mesh using requests
"""
# get a unit cube from project's github
mesh = g.trimesh.io.load.load_remote(
url='https://github.com/mikedh/trimesh/raw/master/models/unit_cube.STL')
# get a unit cube from localhost
with g.serve_meshes() as address:
mesh = g.trimesh.io.load.load_remote(
url=address + '/unit_cube.STL')

assert g.np.isclose(mesh.volume, 1.0)
assert isinstance(mesh, g.trimesh.Trimesh)
Expand Down

0 comments on commit 24e7d85

Please sign in to comment.