Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_output_format_option(self):
opt = options.normalize_options({"output_format": "glb"})
assert opt["output_format"] == "glb"
opt = options.normalize_options({"output_format": "gltf"})
assert opt["output_format"] == "gltf"
opt = options.normalize_options({"output_format": "glTF"})
assert opt["output_format"] == "gltf"
with pytest.raises(ValueError):
options.normalize_options({"output_format": "foobar"})
def test_no_parameter_returns_default_options(self):
opt = options.normalize_options()
assert opt is not options.DEFAULT_OPTIONS
for k, v in options.DEFAULT_OPTIONS.items():
assert k in opt
assert opt[k] == v
def test_no_textures_optimization(self):
opt = options.normalize_options({"no_textures_optimization": True})
assert opt["no_textures_optimization"] is True
opt = options.normalize_options({"no_textures_optimization": False})
assert opt["no_textures_optimization"] is False
opt = options.normalize_options({"no_textures_optimization": ""})
assert opt["no_textures_optimization"] is False
opt = options.normalize_options({"no_textures_optimization": "foobar"})
assert opt["no_textures_optimization"] is True
def test_no_meshes_optimization(self):
opt = options.normalize_options({"no_meshes_optimization": True})
assert opt["no_meshes_optimization"] is True
opt = options.normalize_options({"no_meshes_optimization": False})
assert opt["no_meshes_optimization"] is False
opt = options.normalize_options({"no_meshes_optimization": ""})
assert opt["no_meshes_optimization"] is False
opt = options.normalize_options({"no_meshes_optimization": "foobar"})
assert opt["no_meshes_optimization"] is True
def test_no_graph_optimization(self):
opt = options.normalize_options({"no_graph_optimization": True})
assert opt["no_graph_optimization"] is True
opt = options.normalize_options({"no_graph_optimization": False})
assert opt["no_graph_optimization"] is False
opt = options.normalize_options({"no_graph_optimization": ""})
assert opt["no_graph_optimization"] is False
opt = options.normalize_options({"no_graph_optimization": "foobar"})
assert opt["no_graph_optimization"] is True
def test_no_meshes_optimization(self):
opt = options.normalize_options({"no_meshes_optimization": True})
assert opt["no_meshes_optimization"] is True
opt = options.normalize_options({"no_meshes_optimization": False})
assert opt["no_meshes_optimization"] is False
opt = options.normalize_options({"no_meshes_optimization": ""})
assert opt["no_meshes_optimization"] is False
opt = options.normalize_options({"no_meshes_optimization": "foobar"})
assert opt["no_meshes_optimization"] is True
def test_output_format_option(self):
opt = options.normalize_options({"output_format": "glb"})
assert opt["output_format"] == "glb"
opt = options.normalize_options({"output_format": "gltf"})
assert opt["output_format"] == "gltf"
opt = options.normalize_options({"output_format": "glTF"})
assert opt["output_format"] == "gltf"
with pytest.raises(ValueError):
options.normalize_options({"output_format": "foobar"})
def optimize(input_file, output_file, options={}, textures=None,
verbose=False, quiet=False):
# TODO: Make a effective documentation.
# The textures arguments should be a dictionary that maps
# paths to bytes. When not None, there will be no file system
# reads in order to find referenced textures. We will
# look into that dictionary instead.
model_options = normalize_options(options)
image_options = extract_image_options(options)
if quiet:
verbose = False
# Open file if possible
if not hasattr(input_file, "read"):
input_file = open(input_file, "rb")
root_path = None
if hasattr(input_file, "name"):
root_path = os.path.dirname(os.path.abspath(input_file.name))
# input_file -> string (path), bytes, file-like
if hasattr(input_file, "read"):
input_file = input_file.read()