File: test_client_unit.py

package info (click to toggle)
python-azure 20230112%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 749,544 kB
  • sloc: python: 6,815,827; javascript: 287; makefile: 195; xml: 109; sh: 105
file content (106 lines) | stat: -rw-r--r-- 3,709 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import sys
import pytest
import unittest
from unittest.mock import Mock
from devtools_testutils import AzureTestCase
from azure.core.credentials import AzureKeyCredential
from azure.maps.search.models import StructuredAddress
from azure.maps.search import MapsSearchClient
from azure.maps.search._shared import converter

# cSpell:disable
class AzureMapsSearchClientUnitTest(AzureTestCase):

    def test_fuzzy_search_invalid_top(self):
        client = MapsSearchClient(
            credential=Mock(AzureKeyCredential)
        )
        with pytest.raises(TypeError):
            client.search_point_of_interest_category(StructuredAddress())

    def test_search_structured_address(self):
        client = MapsSearchClient(
            credential=Mock(AzureKeyCredential)
        )
        with pytest.raises(TypeError):
             client.search_structured_address(StructuredAddress())

class TestConverter(unittest.TestCase):

    def test_geo_interface_to_geojson(self):
        data_input= {
            'type': 'Polygon',
            'coordinates': ((
                (-122.43576049804686, 37.7524152343544),
                (-122.43301391601562, 37.70660472542312),
                (-122.36434936523438, 37.712059855877314),
                (-122.43576049804686, 37.7524152343544)
            ),)}

        data_output = {
            'type': 'Polygon',
            'coordinates': [[
                [-122.43576049804686, 37.7524152343544],
                [-122.43301391601562, 37.70660472542312],
                [-122.36434936523438, 37.712059855877314],
                [-122.43576049804686, 37.7524152343544]]
            ]}

        g_json = converter.geo_interface_to_geojson(data_input)
        self.assertEqual(g_json, data_output)

    def test_wkt_to_geo_interface(self):
        data_input= 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'

        data_output = {
            'type': 'Polygon',
            'coordinates': [[
                (30, 10), (40, 40), (20, 40), (10, 20), (30, 10)
            ]]}

        g_interface = converter.wkt_to_geo_interface(data_input)
        self.assertEqual(g_interface, data_output)

    def test_wkt_to_geojson(self):
        data_input= 'POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'

        data_output = {
            'type': 'Polygon',
            'coordinates': [[
                [30, 10], [40, 40], [20, 40], [10, 20], [30, 10]
            ]]}

        g_json = converter.wkt_to_geojson(data_input)
        self.assertEqual(g_json, data_output)

    def test_parse_geometry_input_with_geo_json_obj(self):
        data_input= {
        'type': 'Polygon',
        'coordinates': [[
            [-122.43576049804686, 37.7524152343544],
            [-122.43301391601562, 37.70660472542312],
            [-122.36434936523438, 37.712059855877314],
            [-122.43576049804686, 37.7524152343544]
        ]]}

        data_output = {'geometry': {'type': 'Polygon',
            'coordinates': [[
                [-122.43576049804686, 37.7524152343544],
                [-122.43301391601562, 37.70660472542312],
                [-122.36434936523438, 37.712059855877314],
                [-122.43576049804686, 37.7524152343544]
            ]]}}

        g_obj = converter.parse_geometry_input(data_input)
        self.assertEqual(g_obj, data_output)

if __name__ == "__main__" :
    testArgs = [ "-v" , "-s" ] if len(sys.argv) == 1 else sys.argv[1:]
    #testArgs = [ "-s" , "-n" , "auto" , "--dist=loadscope" ] if len(sys.argv) == 1 else sys.argv[1:]
    #pytest-xdist: -n auto --dist=loadscope
    #pytest-parallel: --tests-per-worker auto
    #print( "testArgs={}".format(testArgs) )

    pytest.main(args=testArgs)

    print("main() Leave")