Merge pull request #9523 from Ultimaker/fix_tests_python_upgrade

Fix tests python upgrade
This commit is contained in:
Remco Burema 2021-04-08 11:49:38 +02:00 committed by GitHub
commit 37cd12663b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 31 deletions

View File

@ -3,7 +3,7 @@
import numpy import numpy
import copy import copy
from typing import Optional, Tuple, TYPE_CHECKING from typing import Optional, Tuple, TYPE_CHECKING, Union
from UM.Math.Polygon import Polygon from UM.Math.Polygon import Polygon
@ -14,14 +14,14 @@ if TYPE_CHECKING:
class ShapeArray: class ShapeArray:
"""Polygon representation as an array for use with :py:class:`cura.Arranging.Arrange.Arrange`""" """Polygon representation as an array for use with :py:class:`cura.Arranging.Arrange.Arrange`"""
def __init__(self, arr: numpy.array, offset_x: float, offset_y: float, scale: float = 1) -> None: def __init__(self, arr: numpy.ndarray, offset_x: float, offset_y: float, scale: float = 1) -> None:
self.arr = arr self.arr = arr
self.offset_x = offset_x self.offset_x = offset_x
self.offset_y = offset_y self.offset_y = offset_y
self.scale = scale self.scale = scale
@classmethod @classmethod
def fromPolygon(cls, vertices: numpy.array, scale: float = 1) -> "ShapeArray": def fromPolygon(cls, vertices: numpy.ndarray, scale: float = 1) -> "ShapeArray":
"""Instantiate from a bunch of vertices """Instantiate from a bunch of vertices
:param vertices: :param vertices:
@ -98,7 +98,7 @@ class ShapeArray:
return offset_shape_arr, hull_shape_arr return offset_shape_arr, hull_shape_arr
@classmethod @classmethod
def arrayFromPolygon(cls, shape: Tuple[int, int], vertices: numpy.array) -> numpy.array: def arrayFromPolygon(cls, shape: Union[Tuple[int, int], numpy.ndarray], vertices: numpy.ndarray) -> numpy.ndarray:
"""Create :py:class:`numpy.ndarray` with dimensions defined by shape """Create :py:class:`numpy.ndarray` with dimensions defined by shape
Fills polygon defined by vertices with ones, all other values zero Fills polygon defined by vertices with ones, all other values zero
@ -110,7 +110,7 @@ class ShapeArray:
:return: numpy array with dimensions defined by shape :return: numpy array with dimensions defined by shape
""" """
base_array = numpy.zeros(shape, dtype = numpy.int32) # Initialize your array of zeros base_array = numpy.zeros(shape, dtype = numpy.int32) # type: ignore # Initialize your array of zeros
fill = numpy.ones(base_array.shape) * True # Initialize boolean array defining shape fill fill = numpy.ones(base_array.shape) * True # Initialize boolean array defining shape fill
@ -126,7 +126,7 @@ class ShapeArray:
return base_array return base_array
@classmethod @classmethod
def _check(cls, p1: numpy.array, p2: numpy.array, base_array: numpy.array) -> Optional[numpy.array]: def _check(cls, p1: numpy.ndarray, p2: numpy.ndarray, base_array: numpy.ndarray) -> Optional[numpy.ndarray]:
"""Return indices that mark one side of the line, used by arrayFromPolygon """Return indices that mark one side of the line, used by arrayFromPolygon
Uses the line defined by p1 and p2 to check array of Uses the line defined by p1 and p2 to check array of

View File

@ -65,7 +65,7 @@ class LayerPolygon:
# When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType # When type is used as index returns true if type == LayerPolygon.InfillType or type == LayerPolygon.SkinType or type == LayerPolygon.SupportInfillType
# Should be generated in better way, not hardcoded. # Should be generated in better way, not hardcoded.
self._is_infill_or_skin_type_map = numpy.array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], dtype = numpy.bool) self._is_infill_or_skin_type_map = numpy.array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], dtype = bool)
self._build_cache_line_mesh_mask = None # type: Optional[numpy.ndarray] self._build_cache_line_mesh_mask = None # type: Optional[numpy.ndarray]
self._build_cache_needed_points = None # type: Optional[numpy.ndarray] self._build_cache_needed_points = None # type: Optional[numpy.ndarray]
@ -73,18 +73,17 @@ class LayerPolygon:
def buildCache(self) -> None: def buildCache(self) -> None:
# For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out. # For the line mesh we do not draw Infill or Jumps. Therefore those lines are filtered out.
self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype = bool) self._build_cache_line_mesh_mask = numpy.ones(self._jump_mask.shape, dtype = bool)
mesh_line_count = numpy.sum(self._build_cache_line_mesh_mask)
self._index_begin = 0 self._index_begin = 0
self._index_end = mesh_line_count self._index_end = cast(int, numpy.sum(self._build_cache_line_mesh_mask))
self._build_cache_needed_points = numpy.ones((len(self._types), 2), dtype = numpy.bool) self._build_cache_needed_points = numpy.ones((len(self._types), 2), dtype = bool)
# Only if the type of line segment changes do we need to add an extra vertex to change colors # Only if the type of line segment changes do we need to add an extra vertex to change colors
self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1] self._build_cache_needed_points[1:, 0][:, numpy.newaxis] = self._types[1:] != self._types[:-1]
# Mark points as unneeded if they are of types we don't want in the line mesh according to the calculated mask # Mark points as unneeded if they are of types we don't want in the line mesh according to the calculated mask
numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask, self._build_cache_needed_points ) numpy.logical_and(self._build_cache_needed_points, self._build_cache_line_mesh_mask, self._build_cache_needed_points )
self._vertex_begin = 0 self._vertex_begin = 0
self._vertex_end = numpy.sum( self._build_cache_needed_points ) self._vertex_end = cast(int, numpy.sum(self._build_cache_needed_points))
def build(self, vertex_offset: int, index_offset: int, vertices: numpy.ndarray, colors: numpy.ndarray, line_dimensions: numpy.ndarray, feedrates: numpy.ndarray, extruders: numpy.ndarray, line_types: numpy.ndarray, indices: numpy.ndarray) -> None: def build(self, vertex_offset: int, index_offset: int, vertices: numpy.ndarray, colors: numpy.ndarray, line_dimensions: numpy.ndarray, feedrates: numpy.ndarray, extruders: numpy.ndarray, line_types: numpy.ndarray, indices: numpy.ndarray) -> None:
"""Set all the arrays provided by the function caller, representing the LayerPolygon """Set all the arrays provided by the function caller, representing the LayerPolygon

View File

@ -1,6 +1,6 @@
# Copyright (c) 2021 Ultimaker B.V. # Copyright (c) 2021 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from typing import Type, TYPE_CHECKING from typing import Type, TYPE_CHECKING, Optional, List
import keyring import keyring
from keyring.backend import KeyringBackend from keyring.backend import KeyringBackend
@ -20,14 +20,15 @@ if Platform.isWindows() and hasattr(sys, "frozen"):
keyring.set_keyring(WinVaultKeyring()) keyring.set_keyring(WinVaultKeyring())
# Even if errors happen, we don't want this stored locally: # Even if errors happen, we don't want this stored locally:
DONT_EVER_STORE_LOCALLY = ["refresh_token"] DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"]
class KeyringAttribute: class KeyringAttribute:
""" """
Descriptor for attributes that need to be stored in the keyring. With Fallback behaviour to the preference cfg file Descriptor for attributes that need to be stored in the keyring. With Fallback behaviour to the preference cfg file
""" """
def __get__(self, instance: Type["BaseModel"], owner: type) -> str: def __get__(self, instance: "BaseModel", owner: type) -> Optional[str]:
if self._store_secure: if self._store_secure: # type: ignore
try: try:
value = keyring.get_password("cura", self._keyring_name) value = keyring.get_password("cura", self._keyring_name)
return value if value != "" else None return value if value != "" else None
@ -38,7 +39,7 @@ class KeyringAttribute:
else: else:
return getattr(instance, self._name) return getattr(instance, self._name)
def __set__(self, instance: Type["BaseModel"], value: str): def __set__(self, instance: "BaseModel", value: Optional[str]):
if self._store_secure: if self._store_secure:
setattr(instance, self._name, None) setattr(instance, self._name, None)
try: try:

View File

@ -25,8 +25,8 @@ class Snapshot:
pixels = numpy.frombuffer(pixel_array, dtype=numpy.uint8).reshape([height, width, 4]) pixels = numpy.frombuffer(pixel_array, dtype=numpy.uint8).reshape([height, width, 4])
# Find indices of non zero pixels # Find indices of non zero pixels
nonzero_pixels = numpy.nonzero(pixels) nonzero_pixels = numpy.nonzero(pixels)
min_y, min_x, min_a_ = numpy.amin(nonzero_pixels, axis=1) min_y, min_x, min_a_ = numpy.amin(nonzero_pixels, axis=1) # type: ignore
max_y, max_x, max_a_ = numpy.amax(nonzero_pixels, axis=1) max_y, max_x, max_a_ = numpy.amax(nonzero_pixels, axis=1) # type: ignore
return min_x, max_x, min_y, max_y return min_x, max_x, min_y, max_y

View File

@ -157,22 +157,22 @@ class AMFReader(MeshReader):
tri_faces = tri_node.faces tri_faces = tri_node.faces
tri_vertices = tri_node.vertices tri_vertices = tri_node.vertices
indices = [] indices_list = []
vertices = [] vertices_list = []
index_count = 0 index_count = 0
face_count = 0 face_count = 0
for tri_face in tri_faces: for tri_face in tri_faces:
face = [] face = []
for tri_index in tri_face: for tri_index in tri_face:
vertices.append(tri_vertices[tri_index]) vertices_list.append(tri_vertices[tri_index])
face.append(index_count) face.append(index_count)
index_count += 1 index_count += 1
indices.append(face) indices_list.append(face)
face_count += 1 face_count += 1
vertices = numpy.asarray(vertices, dtype = numpy.float32) vertices = numpy.asarray(vertices_list, dtype = numpy.float32)
indices = numpy.asarray(indices, dtype = numpy.int32) indices = numpy.asarray(indices_list, dtype = numpy.int32)
normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count) normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count)
mesh_data = MeshData(vertices = vertices, indices = indices, normals = normals,file_name = file_name) mesh_data = MeshData(vertices = vertices, indices = indices, normals = normals,file_name = file_name)

View File

@ -145,22 +145,22 @@ class TrimeshReader(MeshReader):
tri_faces = tri_node.faces tri_faces = tri_node.faces
tri_vertices = tri_node.vertices tri_vertices = tri_node.vertices
indices = [] indices_list = []
vertices = [] vertices_list = []
index_count = 0 index_count = 0
face_count = 0 face_count = 0
for tri_face in tri_faces: for tri_face in tri_faces:
face = [] face = []
for tri_index in tri_face: for tri_index in tri_face:
vertices.append(tri_vertices[tri_index]) vertices_list.append(tri_vertices[tri_index])
face.append(index_count) face.append(index_count)
index_count += 1 index_count += 1
indices.append(face) indices_list.append(face)
face_count += 1 face_count += 1
vertices = numpy.asarray(vertices, dtype = numpy.float32) vertices = numpy.asarray(vertices_list, dtype = numpy.float32)
indices = numpy.asarray(indices, dtype = numpy.int32) indices = numpy.asarray(indices_list, dtype = numpy.int32)
normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count) normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count)
mesh_data = MeshData(vertices = vertices, indices = indices, normals = normals, file_name = file_name) mesh_data = MeshData(vertices = vertices, indices = indices, normals = normals, file_name = file_name)

View File

@ -102,7 +102,7 @@ class VersionUpgrade48to49(VersionUpgrade):
if "shell" in parser: if "shell" in parser:
for setting in parser["shell"]: for setting in parser["shell"]:
if setting in self._moved_visibility_settings: if setting in self._moved_visibility_settings:
parser["top_bottom"][setting] = None parser["top_bottom"][setting] = None # type: ignore
del parser["shell"][setting] del parser["shell"][setting]
result = io.StringIO() result = io.StringIO()