diff --git a/test_container/tests/test/standard-flavor/all/import_r_modules.py b/test_container/tests/test/standard-flavor/all/import_r_modules.py index cfb1bdf6..e8b58435 100644 --- a/test_container/tests/test/standard-flavor/all/import_r_modules.py +++ b/test_container/tests/test/standard-flavor/all/import_r_modules.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from typing import List +from typing import List, Tuple from exasol_python_test_framework import udf from exasol_python_test_framework.udf.udf_debug import UdfDebugger @@ -9,10 +9,10 @@ class ImportAllModulesTest(udf.TestCase): def setUp(self): self.query('create schema import_all_r_modules', ignore_errors=True) - def get_all_root_modules(self) -> List[str]: + def get_all_root_modules(self) -> List[Tuple[str, str]]: self.query(udf.fixindent(''' CREATE OR REPLACE r SCALAR SCRIPT import_all_r_modules.get_all_root_modules() - EMITS (module_name VARCHAR(200000)) AS + EMITS (module_name VARCHAR(200000), version VARCHAR(200)) AS run <- function(ctx) { library(data.table) file_pattern <- "cran_packages" @@ -21,24 +21,30 @@ def get_all_root_modules(self) -> List[str]: for (file in files) { package_list <- fread(file, sep="|", header = FALSE, col.names = c("Package", "Version")) package_names <- package_list[[1]] - ctx$emit(package_names) + versions <- package_list[[2]] + ctx$emit(package_names, versions) } } / ''')) rows = self.query('''SELECT import_all_r_modules.get_all_root_modules() FROM dual''') print("Number of modules:",len(rows)) - root_modules = [row[0] for row in rows] + root_modules = [(row[0], row[1]) for row in rows] print(f"Found {len(root_modules)} root modules.") return root_modules def create_check_installed_package_udf(self): self.query(udf.fixindent(''' CREATE OR REPLACE r SCALAR SCRIPT - import_all_r_modules.check_installed_package(package_name VARCHAR(200000)) + import_all_r_modules.check_installed_package(package_name VARCHAR(200000), version VARCHAR(200)) RETURNS DECIMAL(11,0) AS run <- function(ctx) { library(ctx$package_name, character.only = TRUE) + desc <- packageDescription(ctx$package_name) + if (ctx$version != desc$Version) { + stop(paste("Version of installed installed package does not match:", ctx$package_name)) + return(1) + } 0 } / @@ -50,7 +56,7 @@ def test_import_all_modules(self): self.create_check_installed_package_udf() for root_module in root_modules: # with UdfDebugger(test_case=self): - rows = self.query(f'''SELECT import_all_r_modules.check_installed_package('{root_module}') FROM dual''') + rows = self.query(f'''SELECT import_all_r_modules.check_installed_package('{root_module[0]}', '{root_module[1]}') FROM dual''') def tearDown(self): self.query("drop schema import_all_r_modules cascade", ignore_errors=True)