Skip to content

Commit

Permalink
Added version check in import_r_modules.py integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuben committed Nov 21, 2024
1 parent 5c938f6 commit b509a0a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions test_container/tests/test/standard-flavor/all/import_r_modules.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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
}
/
Expand All @@ -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)
Expand Down

0 comments on commit b509a0a

Please sign in to comment.