1+ # Licensed to the Apache Software Foundation (ASF) under one
2+ # or more contributor license agreements. See the NOTICE file
3+ # distributed with this work for additional information
4+ # regarding copyright ownership. The ASF licenses this file
5+ # to you under the Apache License, Version 2.0 (the
6+ # "License"); you may not use this file except in compliance
7+ # with the License. You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing,
12+ # software distributed under the License is distributed on an
13+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ # KIND, either express or implied. See the License for the
15+ # specific language governing permissions and limitations
16+ # under the License.
117
218import unittest
319import sys
420from unittest .mock import MagicMock , patch
521from pyspark .sql import SparkSession , DataFrame
622from sedona .spark import *
723
24+
825class TestToSedonaDB (unittest .TestCase ):
926
1027 def setUp (self ):
1128 # Mock sedona.db to avoid ImportError
1229 self .mock_sedona_db = MagicMock ()
1330 sys .modules ["sedona.db" ] = self .mock_sedona_db
1431 import sedona
32+
1533 sedona .db = self .mock_sedona_db
1634 self .spark = SparkSession .builder .getOrCreate ()
1735
1836 def tearDown (self ):
1937 if "sedona.db" in sys .modules :
2038 del sys .modules ["sedona.db" ]
2139 import sedona
40+
2241 if hasattr (sedona , "db" ):
2342 del sedona .db
2443
25- @patch (' sedona.spark.dataframe_to_arrow' )
44+ @patch (" sedona.spark.dataframe_to_arrow" )
2645 def test_to_sedonadb_no_connection (self , mock_dataframe_to_arrow ):
2746 # Mock dependencies
2847 mock_arrow_table = MagicMock ()
2948 mock_dataframe_to_arrow .return_value = mock_arrow_table
30-
49+
3150 mock_connection = MagicMock ()
3251 self .mock_sedona_db .connect .return_value = mock_connection
33-
52+
3453 mock_sedonadb_df = MagicMock ()
3554 mock_connection .create_data_frame .return_value = mock_sedonadb_df
3655
3756 # Create a dummy Spark DataFrame
3857 df = self .spark .range (1 )
39-
58+
4059 # Call the method
4160 result = df .to_sedonadb ()
4261
@@ -46,19 +65,19 @@ def test_to_sedonadb_no_connection(self, mock_dataframe_to_arrow):
4665 mock_connection .create_data_frame .assert_called_once_with (mock_arrow_table )
4766 self .assertEqual (result , mock_sedonadb_df )
4867
49- @patch (' sedona.spark.dataframe_to_arrow' )
68+ @patch (" sedona.spark.dataframe_to_arrow" )
5069 def test_to_sedonadb_with_connection (self , mock_dataframe_to_arrow ):
5170 # Mock dependencies
5271 mock_arrow_table = MagicMock ()
5372 mock_dataframe_to_arrow .return_value = mock_arrow_table
54-
73+
5574 mock_connection = MagicMock ()
5675 mock_sedonadb_df = MagicMock ()
5776 mock_connection .create_data_frame .return_value = mock_sedonadb_df
5877
5978 # Create a dummy Spark DataFrame
6079 df = self .spark .range (1 )
61-
80+
6281 # Call the method
6382 result = df .to_sedonadb (connection = mock_connection )
6483
@@ -67,5 +86,6 @@ def test_to_sedonadb_with_connection(self, mock_dataframe_to_arrow):
6786 mock_connection .create_data_frame .assert_called_once_with (mock_arrow_table )
6887 self .assertEqual (result , mock_sedonadb_df )
6988
70- if __name__ == '__main__' :
89+
90+ if __name__ == "__main__" :
7191 unittest .main ()
0 commit comments