Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed Jul 17, 2024
1 parent 15cb027 commit a6b1e0a
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions scripts/irods/test/test_prep_genquery_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,26 +832,25 @@ def tearDown(self):

super(Test_Genquery_Iterator, self).tearDown()

# TODO Replace issue_NNNN with real issue number.
@unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-python', 'Requires PREP.')
def test_genquery_constructor_raises_exception_on_invalid_parser_argument__issue_NNNN(self):
def test_genquery_constructor_raises_exception_on_invalid_parser_argument__issue_7909(self):
with temporary_core_file() as core:
attr_name = 'issue_NNNN_genquery2_error'
attr_name = 'test_genquery_constructor_raises_exception_on_invalid_parser_argument__issue_7909_error'

# The following rule triggers and attaches the exception message generated
# by the invalid parser argument to the Query constructor.
core.add_rule(dedent(f'''
def pep_api_touch_pre(rule_args, callback, rei):
try:
import genquery
gq = genquery.Query(callback, 'COLL_NAME', parser=None)
_ = genquery.Query(callback, 'COLL_NAME', parser=None)
except ValueError as e:
callback.msiModAVUMetadata('-C', '{self.admin.session_collection}', 'add', '{attr_name}', str(e), '')
'''))

# Trigger the PEP.
# This will cause the rule to add an AVU to the session collection.
self.admin.assert_icommand(['itouch', 'issue_NNNN'], 'STDERR')
self.admin.assert_icommand(['itouch', 'issue_7909'], 'STDERR')

# Show the AVU containing the error exists on the session collection.
expected_output = [
Expand All @@ -860,10 +859,9 @@ def pep_api_touch_pre(rule_args, callback, rei):
]
self.admin.assert_icommand(['imeta', 'ls', '-C', self.admin.session_collection], 'STDOUT', expected_output)

# TODO Replace issue_NNNN with real issue number.
@unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-python', 'Requires PREP.')
def test_genquery_iterator_supports_genquery2__issue_NNNN(self):
rule_file = f'{self.admin.local_session_dir}/issue_NNNN.r'
def test_genquery_iterator_supports_genquery2__issue_7909(self):
rule_file = f'{self.admin.local_session_dir}/test_genquery_iterator_supports_genquery2__issue_7909.r'

with open(rule_file, 'w') as rf:
rf.write(dedent(f'''
Expand All @@ -880,16 +878,15 @@ def main(rule_args, callback, rei):
expected_output = [f"row: ['{self.admin.session_collection}']"]
self.admin.assert_icommand(['irule', '-r', rep_instance, '-F', rule_file], 'STDOUT', expected_output)

# TODO Replace issue_NNNN with real issue number.
@unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-python', 'Requires PREP.')
def test_genquery_iterator_supports_genquery2_offset_and_limit__issue_NNNN(self):
def test_genquery_iterator_supports_genquery2_offset_and_limit__issue_7909(self):
# Create some data objects.
data_name_prefix = 'issue_NNNN'
data_name_prefix = 'test_genquery_iterator_supports_genquery2_offset_and_limit__issue_7909'
for i in range(10):
self.admin.assert_icommand(['itouch', f'{data_name_prefix}.{i}'])

# Test offset functionality.
rule_file = f'{self.admin.local_session_dir}/issue_NNNN.r'
rule_file = f'{self.admin.local_session_dir}/test_genquery_iterator_supports_genquery2_offset_and_limit__issue_7909.r'
with open(rule_file, 'w') as rf:
rf.write(dedent(f'''
def main(rule_args, callback, rei):
Expand Down Expand Up @@ -924,3 +921,28 @@ def main(rule_args, callback, rei):
rep_instance = IrodsConfig().default_rule_engine_plugin + '-instance'
expected_output = ['count: 2']
self.admin.assert_icommand(['irule', '-r', rep_instance, '-F', rule_file], 'STDOUT', expected_output)

@unittest.skipUnless(plugin_name == 'irods_rule_engine_plugin-python', 'Requires PREP.')
def test_genquery_iterator_supports_reusing_genquery2_query_object__issue_7909(self):
rule_file = f'{self.admin.local_session_dir}/test_genquery_iterator_supports_reusing_genquery2_query_object__issue_7909.r'

with open(rule_file, 'w') as rf:
rf.write(dedent(f'''
def main(rule_args, callback, rei):
from genquery import Query, Parser
query = Query(callback, 'COLL_NAME', "COLL_NAME = '{self.admin.session_collection}'", parser=Parser.GENQUERY2)
for i in range(3):
for r in query:
callback.writeLine('stdout', f'[iteration={{i}}] row: {{r}}')
INPUT null
OUTPUT ruleExecOut
'''))

# Execute the rule.
rep_instance = IrodsConfig().default_rule_engine_plugin + '-instance'
expected_output = [
f"[iteration=0] row: ['{self.admin.session_collection}']",
f"[iteration=1] row: ['{self.admin.session_collection}']",
f"[iteration=2] row: ['{self.admin.session_collection}']"
]
self.admin.assert_icommand(['irule', '-r', rep_instance, '-F', rule_file], 'STDOUT', expected_output)

0 comments on commit a6b1e0a

Please sign in to comment.