Skip to content

Commit

Permalink
fixed poetry; add dummy tests to test path
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jan 18, 2024
1 parent f0f9050 commit 7f497ed
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 143 deletions.
73 changes: 6 additions & 67 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,3 @@ devtools = "^0.12.2"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = "specklepy_qt_ui"
80 changes: 44 additions & 36 deletions speckle/converter/layers/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,38 @@
import os
import time
from tokenize import String
from typing import List
from typing import List, Union
from plugin_utils.helpers import findOrCreatePath
from qgis._core import (
QgsCoordinateTransform,
Qgis,
QgsPointXY,
QgsGeometry,
QgsRasterBandStats,
QgsFeature,
QgsFields,
QgsField,
QgsVectorLayer,
QgsRasterLayer,
QgsCoordinateReferenceSystem,
QgsProject,
QgsUnitTypes,
)

try:
from qgis._core import (
QgsCoordinateTransform,
Qgis,
QgsPointXY,
QgsGeometry,
QgsRasterBandStats,
QgsFeature,
QgsFields,
QgsField,
QgsVectorLayer,
QgsRasterLayer,
QgsCoordinateReferenceSystem,
QgsProject,
QgsUnitTypes,
)
from osgeo import ( # # C:\Program Files\QGIS 3.20.2\apps\Python39\Lib\site-packages\osgeo
gdal,
osr,
)
from PyQt5.QtCore import QVariant, QDate, QDateTime
except ModuleNotFoundError:
pass

from specklepy.objects import Base
from specklepy.objects.other import RevitParameter

from typing import Dict, Any

from PyQt5.QtCore import QVariant, QDate, QDateTime
from speckle.converter.geometry.conversions import (
convertToNative,
convertToNativeMulti,
Expand Down Expand Up @@ -57,17 +66,14 @@
traverseDict,
validateAttributeName,
)
from osgeo import ( # # C:\Program Files\QGIS 3.20.2\apps\Python39\Lib\site-packages\osgeo
gdal,
osr,
)

import numpy as np
import scipy as sp

from speckle.utils.panel_logging import logToUser


def addFeatVariant(key, variant, value, f: QgsFeature):
def addFeatVariant(key, variant, value, f: "QgsFeature"):
# print("__________add variant")
try:
feat = f
Expand Down Expand Up @@ -105,7 +111,9 @@ def addFeatVariant(key, variant, value, f: QgsFeature):
return feat


def updateFeat(feat: QgsFeature, fields: QgsFields, feature: Base) -> dict[str, Any]:
def updateFeat(
feat: "QgsFeature", fields: "QgsFields", feature: Base
) -> dict[str, Any]:
try:
# print("__updateFeat")
all_field_names = fields.names()
Expand Down Expand Up @@ -174,12 +182,12 @@ def updateFeat(feat: QgsFeature, fields: QgsFields, feature: Base) -> dict[str,

def featureToSpeckle(
fieldnames: List[str],
f: QgsFeature,
f: "QgsFeature",
geomType,
sourceCRS: QgsCoordinateReferenceSystem,
targetCRS: QgsCoordinateReferenceSystem,
project: QgsProject,
selectedLayer: QgsVectorLayer or QgsRasterLayer,
sourceCRS: "QgsCoordinateReferenceSystem",
targetCRS: "QgsCoordinateReferenceSystem",
project: "QgsProject",
selectedLayer: Union["QgsVectorLayer", "QgsRasterLayer"],
dataStorage,
):
# print("Feature to Speckle")
Expand Down Expand Up @@ -297,9 +305,9 @@ def featureToSpeckle(


def rasterFeatureToSpeckle(
selectedLayer: QgsRasterLayer,
projectCRS: QgsCoordinateReferenceSystem,
project: QgsProject,
selectedLayer: "QgsRasterLayer",
projectCRS: "QgsCoordinateReferenceSystem",
project: "QgsProject",
plugin,
) -> Base:
dataStorage = plugin.dataStorage
Expand Down Expand Up @@ -1090,7 +1098,7 @@ def rasterFeatureToSpeckle(
return None


def featureToNative(feature: Base, fields: QgsFields, dataStorage):
def featureToNative(feature: Base, fields: "QgsFields", dataStorage):
feat = QgsFeature()
# print("___featureToNative")
try:
Expand Down Expand Up @@ -1182,9 +1190,9 @@ def featureToNative(feature: Base, fields: QgsFields, dataStorage):


def bimFeatureToNative(
exist_feat: QgsFeature,
exist_feat: "QgsFeature",
feature: Base,
fields: QgsFields,
fields: "QgsFields",
crs,
path: str,
dataStorage,
Expand All @@ -1204,7 +1212,7 @@ def bimFeatureToNative(
return


def nonGeomFeatureToNative(feature: Base, fields: QgsFields, dataStorage):
def nonGeomFeatureToNative(feature: Base, fields: "QgsFields", dataStorage):
try:
exist_feat = QgsFeature()
exist_feat.setFields(fields)
Expand All @@ -1216,7 +1224,7 @@ def nonGeomFeatureToNative(feature: Base, fields: QgsFields, dataStorage):
return


def cadFeatureToNative(feature: Base, fields: QgsFields, dataStorage):
def cadFeatureToNative(feature: Base, fields: "QgsFields", dataStorage):
try:
exist_feat = QgsFeature()
try:
Expand Down
59 changes: 32 additions & 27 deletions speckle/converter/layers/layer_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import time
from datetime import datetime

from osgeo import ( # # C:\Program Files\QGIS 3.20.2\apps\Python39\Lib\site-packages\osgeo
gdal,
osr,
)
from plugin_utils.helpers import (
findFeatColors,
findOrCreatePath,
Expand All @@ -33,28 +29,37 @@
)

# from qgis._core import Qgis, QgsVectorLayer, QgsWkbTypes
from qgis.core import (
Qgis,
QgsProject,
QgsRasterLayer,
QgsPoint,
QgsVectorLayer,
QgsProject,
QgsWkbTypes,
QgsLayerTree,
QgsLayerTreeGroup,
QgsLayerTreeNode,
QgsLayerTreeLayer,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsFields,
QgsSingleSymbolRenderer,
QgsCategorizedSymbolRenderer,
QgsRendererCategory,
QgsSymbol,
QgsUnitTypes,
QgsVectorFileWriter,
)
try:
from qgis.core import (
Qgis,
QgsProject,
QgsRasterLayer,
QgsPoint,
QgsVectorLayer,
QgsProject,
QgsWkbTypes,
QgsLayerTree,
QgsLayerTreeGroup,
QgsLayerTreeNode,
QgsLayerTreeLayer,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsFields,
QgsSingleSymbolRenderer,
QgsCategorizedSymbolRenderer,
QgsRendererCategory,
QgsSymbol,
QgsUnitTypes,
QgsVectorFileWriter,
)
from osgeo import ( # # C:\Program Files\QGIS 3.20.2\apps\Python39\Lib\site-packages\osgeo
gdal,
osr,
)
from PyQt5.QtGui import QColor
except ModuleNotFoundError:
pass

from specklepy.objects.GIS.geometry import GisPolygonElement, GisNonGeometryElement
from speckle.converter.geometry.point import (
pointToNative,
Expand Down Expand Up @@ -102,7 +107,7 @@
rendererToSpeckle,
)

from PyQt5.QtGui import QColor

import numpy as np

from speckle.utils.panel_logging import logToUser
Expand Down
6 changes: 3 additions & 3 deletions speckle/converter/layers/symbology.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import inspect
from typing import Any, Dict, Union
from typing import Any, Dict, Tuple, Union

try:
from qgis.core import (
Expand All @@ -23,11 +23,11 @@
QgsGraduatedSymbolRenderer,
QgsRasterDataProvider,
)
from PyQt5.QtGui import QColor
except ModuleNotFoundError:
pass

from specklepy.objects.GIS.layers import Layer, RasterLayer, VectorLayer
from PyQt5.QtGui import QColor

from speckle.utils.panel_logging import logToUser

Expand Down Expand Up @@ -170,7 +170,7 @@ def gradientColorRampToNative(renderer: dict[str, Any]) -> "QgsGradientColorRamp
return newRamp


def get_r_g_b(rgb: int) -> tuple[int, int, int]:
def get_r_g_b(rgb: int) -> Tuple[int, int, int]:
r = g = b = 0
try:
r = (rgb & 0xFF0000) >> 16
Expand Down
8 changes: 3 additions & 5 deletions speckle/converter/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Mesh,
)

from PyQt5.QtCore import QVariant, QDate, QDateTime

try:
from qgis._core import (
Expand All @@ -30,13 +29,12 @@
QgsFields,
QgsLayerTreeGroup,
)

from PyQt5.QtGui import QColor
from PyQt5.QtCore import QVariant, QDate, QDateTime
from osgeo import gdal, ogr, osr
except ModuleNotFoundError:
pass

from PyQt5.QtGui import QColor


import math
import numpy as np
Expand Down Expand Up @@ -186,7 +184,7 @@ def getLayerGeomType(
return


def getVariantFromValue(value: Any) -> Union[QVariant.Type, None]:
def getVariantFromValue(value: Any) -> Union["QVariant.Type", None]:
try:
# TODO add Base object
pairs = {
Expand Down
1 change: 0 additions & 1 deletion speckle_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from qgis.PyQt import QtWidgets
from qgis import PyQt

# from PyQt5.QtCore import pyqtSignal

import sip

Expand Down
Empty file added tests/unit/__init__.py
Empty file.
14 changes: 13 additions & 1 deletion tests/unit/geometry_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import math
from typing import Union
import pytest

import os
import sys
import speckle
import specklepy_qt_ui

r"""
sys.path.append(
os.path.abspath(
os.path.dirname(speckle.__file__).replace(
"speckle-qgis\\speckle", "speckle-qgis\\specklepy_qt_ui"
)
)
)
"""

from specklepy_qt_ui.qt_ui.DataStorage import DataStorage
# from specklepy_qt_ui.qt_ui.DataStorage import DataStorage

from specklepy.objects.encoding import CurveTypeEncoding
from specklepy.objects.geometry import Arc, Line, Mesh, Point, Plane, Polycurve, Vector


@pytest.fixture()
def data_storage():
class DataStorage:
crs_offset_x: Union[int, float]
crs_offset_y: Union[int, float]
crs_rotation: Union[int, float]

def __init__(self):
pass

sample_obj = DataStorage()
sample_obj.crs_offset_x = 0
sample_obj.crs_offset_y = 0
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/geometry_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
from typing import List, Tuple
import pytest
import os
import sys

from speckle.converter.geometry.utils import (
cross_product,
Expand Down Expand Up @@ -323,3 +325,17 @@ def test_apply_pt_transform_matrix(data_storage):
data_storage.matrix = matrix
result = apply_pt_transform_matrix(pt, data_storage)
assert isinstance(result, Point)


def test_path():
import speckle

p = os.path.abspath(os.path.dirname(speckle.__file__))
t = os.path.abspath(
os.path.dirname(speckle.__file__).replace(
"speckle-qgis\\speckle", "speckle-qgis\\specklepy_qt_ui"
)
)
assert "1" in sys.path
assert p=="1"
assert t=="1"

0 comments on commit 7f497ed

Please sign in to comment.