Skip to content

Commit c217232

Browse files
committed
Add test case for exaslct generate-alter-session
1 parent 3a17a33 commit c217232

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
language_definition=PYTHON=localzmq+protobuf:///{{ bucketfs_name }}/{{ bucket_name }}/{{ path_in_bucket }}/{{ release_name }}?lang=python#buckets/{{ bucketfs_name }}/{{ bucket_name }}/{{ path_in_bucket }}/{{ release_name }}/exaudf/exaudfclient JAVA=builtin_java R=builtin_r
1+
PYTHON=localzmq+protobuf:///{{ bucketfs_name }}/{{ bucket_name }}/{{ path_in_bucket }}{{ release_name }}?lang=python#buckets/{{ bucketfs_name }}/{{ bucket_name }}/{{ path_in_bucket }}{{ release_name }}/exaudf/exaudfclient
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import unittest
2+
3+
import docker
4+
5+
from exaslct_src.lib.utils.docker_utils import find_images_by_tag
6+
from exaslct_src.test import utils
7+
8+
9+
class GenerateAlterSessionTest(unittest.TestCase):
10+
11+
def setUp(self):
12+
print(f"SetUp {self.__class__.__name__}")
13+
self.test_environment = utils.ExaslctTestEnvironment(self)
14+
15+
def test_generate_alter_session_with_path_in_bucket(self):
16+
command = f"./exaslct generate-alter-session --bucketfs-name bfsdefault --bucket-name default --path-in-bucket path --container-name container"
17+
completed_process=self.test_environment.run_command(command,use_docker_repository=False, use_output_directory=False, capture_output=True)
18+
self.assertIn("ALTER SESSION SET SCRIPT_LANGUAGES='PYTHON=localzmq+protobuf:///bfsdefault/default/path/container?lang=python#buckets/bfsdefault/default/path/container/exaudf/exaudfclient';",completed_process.stdout.decode("UTF-8"))
19+
20+
21+
def test_generate_alter_session_without_path_in_bucket(self):
22+
command = f"./exaslct generate-alter-session --bucketfs-name bfsdefault --bucket-name default --container-name container"
23+
completed_process=self.test_environment.run_command(command,use_docker_repository=False, use_output_directory=False, capture_output=True)
24+
self.assertIn("ALTER SESSION SET SCRIPT_LANGUAGES='PYTHON=localzmq+protobuf:///bfsdefault/default/container?lang=python#buckets/bfsdefault/default/container/exaudf/exaudfclient';",completed_process.stdout.decode("UTF-8"))
25+
26+
if __name__ == '__main__':
27+
unittest.main()

exaslct_src/test/utils.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ def clean_images(self):
7171
self.run_command(f"./exaslct clean-flavor-images", clean=True)
7272

7373
def run_command(self, command: str,
74+
use_output_directory: bool = True,
7475
use_flavor_path: bool = True,
7576
use_docker_repository: bool = True,
7677
track_task_dependencies: bool = False,
77-
clean: bool = False):
78-
command = f"{command} {self.output_directory_arguments}"
78+
clean: bool = False,
79+
capture_output: bool = False):
80+
if use_output_directory:
81+
command = f"{command} {self.output_directory_arguments}"
7982
if track_task_dependencies:
8083
command = f"{command} {self.task_dependencies_argument}"
8184
if use_flavor_path:
@@ -86,8 +89,16 @@ def run_command(self, command: str,
8689
command = f"{command} {self.clean_docker_repository_arguments}"
8790
print()
8891
print(f"command: {command}")
89-
completed_process = subprocess.run(shlex.split(command))
90-
completed_process.check_returncode()
92+
if capture_output:
93+
completed_process = subprocess.run(shlex.split(command),stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
94+
else:
95+
completed_process = subprocess.run(shlex.split(command))
96+
try:
97+
completed_process.check_returncode()
98+
except subprocess.CalledProcessError as e:
99+
print(e.stdout.decode("UTF-8"))
100+
raise e
101+
return completed_process
91102

92103
def close(self):
93104
try:

google-cloud-build/ci-scripts/test_branch_exaslct.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ steps:
2020
'run_exaslct_test.sh',
2121
'exaslct_src/test/test_base_task.py'
2222
]
23+
- id: 'Test exaslct test_hash_temp_dir.py'
24+
name: 'gcr.io/script-languages/build-container'
25+
args: [
26+
'bash',
27+
'run_exaslct_test.sh',
28+
'exaslct_src/test/test_hash_temp_dir.py'
29+
]
30+
- id: 'Test exaslct test_generate_alter_session.py'
31+
name: 'gcr.io/script-languages/build-container'
32+
args: [
33+
'bash',
34+
'run_exaslct_test.sh',
35+
'exaslct_src/test/test_generate_alter_session.py'
36+
]
2337
- id: 'Test exaslct test_docker_build.py'
2438
name: 'gcr.io/script-languages/build-container'
2539
args: [
@@ -55,13 +69,6 @@ steps:
5569
'run_exaslct_test.sh',
5670
'exaslct_src/test/test_docker_save.py'
5771
]
58-
- id: 'Test exaslct test_hash_temp_dir.py'
59-
name: 'gcr.io/script-languages/build-container'
60-
args: [
61-
'bash',
62-
'run_exaslct_test.sh',
63-
'exaslct_src/test/test_hash_temp_dir.py'
64-
]
6572
- id: 'Test exaslct test_run_db_test_docker_db.py'
6673
name: 'gcr.io/script-languages/build-container'
6774
args: [

0 commit comments

Comments
 (0)