コード例 #1
0
ファイル: testgeoloc.py プロジェクト: theryee/xlang
    def test_GetGeopositionAsync(self):
        """test async method using IAsyncOperation Completed callback"""
        import threading

        complete_event = threading.Event()

        def callback(operation, status):
            self.assertEqual(status, 1)
            pos = operation.GetResults()

            self.assertEqual(type(pos), wdg.Geoposition)

            coord = pos.Coordinate
            self.assertEqual(type(coord.Timestamp.UniversalTime), int)

            basic_pos = coord.Point.Position
            lat = basic_pos.Latitude
            self.assertEqual(type(lat), float)

            complete_event.set()

        locator = wdg.Geolocator()
        op = locator.GetGeopositionAsync()
        op.Completed = callback

        self.assertTrue(complete_event.wait(5))
コード例 #2
0
ファイル: testgeoloc.py プロジェクト: cnmade/xlang
        async def async_test():
            future = loop.create_future()

            def callback(operation, status):
                if status == 1:
                    result = operation.GetResults()
                    loop.call_soon_threadsafe(asyncio.Future.set_result,
                                              future, result)
                elif status == 2:
                    loop.call_soon_threadsafe(asyncio.Future.set_exception,
                                              future, asyncio.CancelledError())
                elif status == 3:
                    loop.call_soon_threadsafe(asyncio.Future.set_exception,
                                              future,
                                              RuntimeError("AsyncOp failed"))
                else:
                    loop.call_soon_threadsafe(
                        asyncio.Future.set_exception, future,
                        RuntimeError("Unexpected AsyncStatus"))

            locator = wdg.Geolocator()
            op = locator.GetGeopositionAsync()
            op.put_Completed(callback)

            pos = await future
            self.assertEqual(type(pos), wdg.Geoposition)

            coord = pos.get_Coordinate()
            self.assertEqual(type(coord.get_Timestamp().UniversalTime), int)

            basic_pos = coord.get_Point().get_Position()
            lat = basic_pos.Latitude
            self.assertEqual(type(lat), float)
コード例 #3
0
ファイル: testgeoloc.py プロジェクト: theryee/xlang
    async def test_GetGeopositionAsync_await(self):
        """test async method by directly awaiting IAsyncOperation"""

        locator = wdg.Geolocator()
        pos = await locator.GetGeopositionAsync()
        self.assertEqual(type(pos), wdg.Geoposition)

        coord = pos.Coordinate
        self.assertEqual(type(coord.Timestamp.UniversalTime), int)

        basic_pos = coord.Point.Position
        lat = basic_pos.Latitude
        self.assertEqual(type(lat), float)
コード例 #4
0
ファイル: testgeoloc.py プロジェクト: theryee/xlang
 def test_pinterface_qi(self):
     locator = wdg.Geolocator()
     op = locator.GetGeopositionAsync()
     self.assertEqual(type(op), wf.IAsyncOperation)
     op.Cancel()