def testAlgDateTimeInput(self): """ Test datetime parameter """ if Qgis.QGIS_VERSION_INT < 31400: self.skipTest("QGIS version does not support this.") context = QgsProcessingContext() feedback = QgsProcessingFeedback() alg = RAlgorithm(description_file=os.path.join( test_data_path, 'test_input_datetime.rsx')) alg.initAlgorithm() script = alg.build_r_script( {'datetime': QDateTime(QDate(2021, 10, 1), QTime(16, 57, 0))}, context, feedback) self.assertIn( 'datetime <- as.POSIXct("2021-10-01T16:57:00", format = "%Y-%m-%dT%H:%M:%S")', script) script = alg.build_r_script( {'datetime': QDateTime(QDate(2021, 10, 14), QTime(14, 48, 52))}, context, feedback) self.assertIn( 'datetime <- as.POSIXct("2021-10-14T14:48:52", format = "%Y-%m-%dT%H:%M:%S")', script)
def testAlgPointInput(self): """ Test Point parameter """ context = QgsProcessingContext() feedback = QgsProcessingFeedback() alg = RAlgorithm(description_file=os.path.join(test_data_path, 'test_input_point.rsx')) alg.initAlgorithm() script = alg.build_r_script( {'point': '20.219926,49.138354 [EPSG:4326]'}, context, feedback) self.assertIn('library("sf")', script) self.assertIn( 'point <- st_sfc(st_point(c(20.219926,49.138354)), crs = point_crs)', script) alg = RAlgorithm(description_file=os.path.join( test_data_path, 'test_input_point_sp.rsx')) alg.initAlgorithm() script = alg.build_r_script( {'point': '20.219926,49.138354 [EPSG:4326]'}, context, feedback) self.assertIn('library("sp")', script) self.assertIn('xy_df <- cbind(c(20.219926), c(49.138354))', script) self.assertIn('point <- SpatialPoints(xy_df, proj4string = point_crs)', script)
def testAlgExpressions(self): """ Test Expression parameter """ context = QgsProcessingContext() feedback = QgsProcessingFeedback() alg = RAlgorithm(description_file=os.path.join( test_data_path, 'test_input_expression.rsx')) alg.initAlgorithm() script = alg.build_r_script({''}, context, feedback) self.assertIn('number <- 6', script) self.assertTrue( any([ 'geometry <- sf::st_as_sfc("Polygon ' in line for line in script ])) # pylint: disable=use-a-generator self.assertIn( 'date_a <- as.POSIXct("2020-05-04", format = "%Y-%m-%d")', script) self.assertIn('time_a <- lubridate::hms("13:45:30")', script) self.assertIn( 'array <- list(' '2, ' '10, ' '"a", ' 'as.POSIXct("2020-05-04", format = "%Y-%m-%d"), ' 'lubridate::hms("13:45:30"), ' 'as.POSIXct("2012-05-04T10:50:00", format = "%Y-%m-%dT%H:%M:%S"))', script)
def testAlgRangeInput(self): """ Test range parameter """ context = QgsProcessingContext() feedback = QgsProcessingFeedback() alg = RAlgorithm(description_file=os.path.join(test_data_path, 'test_input_range.rsx')) alg.initAlgorithm() script = alg.build_r_script({'range': [0, 1]}, context, feedback) self.assertIn('range <- c(min = 0.0, max = 1.0)', script) script = alg.build_r_script({'range': [5, 10]}, context, feedback) self.assertIn('range <- c(min = 5.0, max = 10.0)', script) script = alg.build_r_script({'range': [0.5, 1.5]}, context, feedback) self.assertIn('range <- c(min = 0.5, max = 1.5)', script)
def testAlgColorInput(self): """ Test color parameter """ context = QgsProcessingContext() feedback = QgsProcessingFeedback() alg = RAlgorithm(description_file=os.path.join(test_data_path, 'test_input_color.rsx')) alg.initAlgorithm() script = alg.build_r_script({'color': QColor(0, 255, 0)}, context, feedback) self.assertIn('color <- rgb(0, 255, 0, 255, maxColorValue = 255)', script) script = alg.build_r_script({'color': QColor(255, 0, 0)}, context, feedback) self.assertIn('color <- rgb(255, 0, 0, 255, maxColorValue = 255)', script)
def testAlgColorInput(self): """ Test color parameter """ if Qgis.QGIS_VERSION_INT < 31000: self.skipTest("QGIS version does not support this.") context = QgsProcessingContext() feedback = QgsProcessingFeedback() alg = RAlgorithm(description_file=os.path.join(test_data_path, 'test_input_color.rsx')) alg.initAlgorithm() script = alg.build_r_script({'color': QColor(0, 255, 0)}, context, feedback) self.assertIn('color <- rgb(0, 255, 0, 255, maxColorValue = 255)', script) script = alg.build_r_script({'color': QColor(255, 0, 0)}, context, feedback) self.assertIn('color <- rgb(255, 0, 0, 255, maxColorValue = 255)', script)
def testAlgDontLoadAnyPackages(self): """ Test dont_load_any_packages keyword """ alg = RAlgorithm(description_file=os.path.join( test_data_path, 'test_dont_load_any_packages.rsx')) alg.initAlgorithm() context = QgsProcessingContext() feedback = QgsProcessingFeedback() script = alg.build_r_script({}, context, feedback) self.assertNotIn('library("sf")', script) self.assertNotIn('library("raster")', script) self.assertNotIn('library("rgdal")', script) self.assertNotIn('library("sp")', script)