diff --git a/.github/workflows/test_package.yaml b/.github/workflows/test_package.yaml index 3f0a91f..e239c4b 100644 --- a/.github/workflows/test_package.yaml +++ b/.github/workflows/test_package.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -34,4 +34,4 @@ jobs: SSO_CLIENT_SECRET: ${{ secrets.SSO_CLIENT_SECRET }} ENVIRONMENT: ${{ vars.ENVIRONMENT }} run: | - pytest tests -s --retries 4 + pytest tests --retries 2 diff --git a/runregistry/runregistry.py b/runregistry/runregistry.py index f8611c2..c53bdb6 100644 --- a/runregistry/runregistry.py +++ b/runregistry/runregistry.py @@ -2,6 +2,7 @@ import time import json import requests +import warnings from dotenv import load_dotenv from cernrequests import get_api_token, get_with_token from runregistry.utils import ( @@ -25,6 +26,16 @@ # Offline table WAITING_DQM_GUI_CONSTANT = "waiting dqm gui" +# Valid Lumisection statuses +LUMISECTION_STATES = ["GOOD", "BAD", "STANDBY", "EXCLUDED", "NOTSET"] + +ONLINE_RUN_STATES = ["SIGNOFF", "OPEN", "COMPLETED"] + +OFFLINE_DATASET_STATES = ["SIGNOFF", "OPEN", "COMPLETED", WAITING_DQM_GUI_CONSTANT] + +# Time to sleep between JSON creation checks +JSON_CREATION_SLEEP_TIME = 15 + staging_cert = "" staging_key = "" api_url = "" @@ -70,14 +81,12 @@ def _get_headers(token: str = ""): def _get_token(): - # if not use_cookies: - # return {"dummy": "yammy"} """ Gets the token required to query RR API through the CERN SSO. - :return: the token required to query Run Registry API. In particular 'connect.sid' is the one we are interested in + :return: the token required to query Run Registry API. """ - # if os.getenv("ENVIRONMENT") == "development": - # return None + if os.getenv("ENVIRONMENT") == "local": + return "" token, expiration_date = get_api_token( client_id=client_id, client_secret=client_secret, @@ -100,7 +109,7 @@ def _get_page( query_filter = transform_to_rr_run_filter(run_filter=query_filter) elif data_type == "datasets" and not ignore_filter_transformation: query_filter = transform_to_rr_dataset_filter(dataset_filter=query_filter) - if os.getenv("ENVIRONMENT") == "development": + if os.getenv("ENVIRONMENT") in ["development", "local"]: print(url) print(query_filter) payload = json.dumps( @@ -130,8 +139,12 @@ def get_run(run_number, **kwargs): :param run_number: run_number of specified run """ run = get_runs(filter={"run_number": run_number}, **kwargs) - if len(run) != 1: - return None + if not run: + return {} + if len(run) > 1: + raise Exception( + f"Unexpected number of results returned for run {run_number} ({len(run)}), was expecting exactly 1" + ) return run[0] @@ -160,10 +173,9 @@ def get_runs(limit=40000, compress_attributes=True, **kwargs): "WARNING: fetching more than 10,000 runs from run registry. you probably want to pass a filter into get_runs, or else this will take a while." ) if resource_count > 20000 and "filter" not in kwargs: - print( + raise Exception( "ERROR: For run registry queries that retrieve more than 20,000 runs, you must pass a filter into get_runs, an empty filter get_runs(filter={}) works" ) - return None for page_number in range(1, page_count): additional_runs = _get_page( page=page_number, url=url, data_type="runs", **kwargs @@ -199,8 +211,12 @@ def get_dataset(run_number, dataset_name="online", **kwargs): dataset = get_datasets( filter={"run_number": run_number, "dataset_name": dataset_name}, **kwargs ) - if len(dataset) != 1: - return None + if not dataset: + return {} + if len(dataset) > 1: + raise Exception( + f"Unexpected number of results returned for dataset {dataset_name} of run {run_number} ({len(dataset)}), was expecting exactly 1" + ) return dataset[0] @@ -228,10 +244,9 @@ def get_datasets(limit=40000, compress_attributes=True, **kwargs) -> list: "WARNING: fetching more than 10,000 datasets. you probably want to pass a filter into get_datasets, or else this will take a while." ) if resource_count > 20000 and "filter" not in kwargs: - print( + raise Exception( "ERROR: For queries that retrieve more than 20,000 datasets, you must pass a filter into get_datasets, an empty filter get_datasets(filter={}) works" ) - return [] for page_number in range(1, page_count): additional_datasets = _get_page( page=page_number, url=url, data_type="datasets", **kwargs @@ -259,14 +274,14 @@ def get_datasets(limit=40000, compress_attributes=True, **kwargs) -> list: def get_cycles(): url = "{}/cycles/global".format(api_url) headers = _get_headers(token=_get_token()) - if os.getenv("ENVIRONMENT") == "development": + if os.getenv("ENVIRONMENT") in ["development", "local"]: print(url) return requests.get(url, headers=headers).json() def _get_lumisection_helper(url, run_number, dataset_name="online", **kwargs): """ - Puts the headers for all other lumisection methods + Puts the headers and POST data for all other lumisection methods """ headers = _get_headers(token=_get_token()) @@ -292,12 +307,28 @@ def get_oms_lumisections(run_number, dataset_name="online", **kwargs): def get_lumisection_ranges(run_number, dataset_name="online", **kwargs): """ - Gets the lumisection ranges of the specified dataset + Gets the lumisection ranges of the specified dataset. Returns + a list of dicts, each one containing a lumisection "range", dictated + by the 'start' and 'stop' keys of the dict. In the same dict, + the status, cause, and comments per component are found. """ url = "{}/lumisections/rr_lumisection_ranges".format(api_url) return _get_lumisection_helper(url, run_number, dataset_name, **kwargs) +def get_lumisection_ranges_by_component(run_number, dataset_name="online", **kwargs): + """ + Gets the lumisection ranges of the specified dataset as a dict, + where the components are the keys (e.g. 'rpc-rpc'). Each dict value is + a list of lumisection "ranges" (dicts) for the specific component. The exact + range is dictated by the 'start' and 'stop' keys of the nested dict. + + Similar to get_lumisection_ranges, but organized by component. + """ + url = "{}/lumisections/rr_lumisection_ranges_by_component".format(api_url) + return _get_lumisection_helper(url, run_number, dataset_name, **kwargs) + + def get_oms_lumisection_ranges(run_number, **kwargs): """ Gets the OMS lumisection ranges of the specified dataset (saved in RR database) @@ -320,6 +351,10 @@ def generate_json(json_logic, **kwargs): DO NOT USE, USE THE ONE BELOW (create_json)... It receives a json logic configuration and returns a json with lumisections which pass the filter """ + warnings.warn( + "The generate_json is unsafe and will be deprecated. Please use create_json instead", + PendingDeprecationWarning, + ) if not isinstance(json_logic, str): json_logic = json.dumps(json_logic) url = "{}/json_creation/generate".format(api_url) @@ -357,21 +392,18 @@ def create_json(json_logic, dataset_name_filter, **kwargs): response = requests.post(url, headers=headers, data=payload) if response.status_code == 200: return response.json()["final_json"] + elif response.status_code == 202: + # stil processing + print(f"progress creating json: {response.json()['progress']}") + time.sleep(JSON_CREATION_SLEEP_TIME) + elif response.status_code == 203: + # stil processing + print("json process is submited and pending, please wait...") + time.sleep(JSON_CREATION_SLEEP_TIME) else: - if response.status_code == 202: - # stil processing - print("progress creating json: ", response.json()["progress"]) - time.sleep(15) - elif response.status_code == 203: - # stil processing - print("json process is submited and pending, please wait...") - time.sleep(15) - elif response.status_code == 500: - print("Error creating json") - return - else: - print("error generating json") - return + raise Exception( + f"Error {response.status_code} during JSON creation: {response.text}" + ) # advanced RR operations ============================================================================== @@ -381,21 +413,13 @@ def move_runs(from_, to_, run=None, runs=[], **kwargs): move run/runs from one state to another """ if not run and not runs: - print("move_runs(): no 'run' and 'runs' arguments were provided") - return + raise ValueError("move_runs(): no 'run' and 'runs' arguments were provided") - states = ["SIGNOFF", "OPEN", "COMPLETED"] - if from_ not in states or to_ not in states: - print( - "move_runs(): get states '", - from_, - "' , '", - to_, - "', while allowed states are ", - states, - ", return", + if from_ not in ONLINE_RUN_STATES or to_ not in ONLINE_RUN_STATES: + raise ValueError( + f"move_runs(): got states '{from_}, '{to_}'", + f" but allowed states are {ONLINE_RUN_STATES}", ) - return url = "%s/runs/move_run/%s/%s" % (api_url, from_, to_) @@ -408,7 +432,7 @@ def move_runs(from_, to_, run=None, runs=[], **kwargs): answers = [] for run_number in runs: payload = json.dumps({"run_number": run_number}) - answer = requests.post(url, headers=headers, data=payload).json() + answer = requests.post(url, headers=headers, data=payload) answers.append(answer) return answers @@ -419,8 +443,9 @@ def make_significant_runs(run=None, runs=[], **kwargs): mark run/runs significant """ if not run and not runs: - print("make_significant_runs(): no 'run' and 'runs' arguments were provided") - return + raise ValueError( + "make_significant_runs(): no 'run' and 'runs' arguments were provided" + ) url = "%s/runs/mark_significant" % (api_url) @@ -445,10 +470,9 @@ def reset_RR_attributes_and_refresh_runs(runs=[], **kwargs): """ runs = __parse_runs_arg(runs) if not runs: - print( - "reset_RR_attributes_and_refresh_runs(): no 'runs' arguments were provided" + raise ValueError( + "reset_RR_attributes_and_refresh_runs(): no 'runs' argument was provided" ) - return headers = _get_headers(token=_get_token()) answers = [] for run_number in runs: @@ -467,10 +491,9 @@ def manually_refresh_components_statuses_for_runs(runs=[], **kwargs): runs = __parse_runs_arg(runs) if not runs: - print( - "manually_refresh_components_statuses_for_runs(): no 'runs' arguments were provided, return" + raise ValueError( + "manually_refresh_components_statuses_for_runs(): no 'runs' argument was provided" ) - return headers = _get_headers(token=_get_token()) answers = [] @@ -496,16 +519,11 @@ def edit_rr_lumisections( """ WIP edit RR lumisections attributes """ - states = ["GOOD", "BAD", "STANDBY", "EXCLUDED", "NONSET"] - if status not in states: - print( - "edit_rr_lumisections(): get status '", - status, - "', while allowed statuses are ", - states, - ", return", + if status not in LUMISECTION_STATES: + raise Exception( + f"edit_rr_lumisections(): got status '{status}'", + f" but allowed statuses are {LUMISECTION_STATES}", ) - return url = "%s/lumisections/edit_rr_lumisections" % (api_url) @@ -535,21 +553,13 @@ def move_datasets( Requires a privileged token. """ if not run and not runs: - print("move_datasets(): no 'run' and 'runs' arguments were provided, return") - return + raise ValueError("move_datasets(): no 'run' and 'runs' arguments were provided") - states = ["SIGNOFF", "OPEN", "COMPLETED", WAITING_DQM_GUI_CONSTANT] - if from_ not in states or to_ not in states: - print( - "move_datasets(): get states '", - from_, - "' , '", - to_, - "', while allowed states are ", - states, - ", return", + if from_ not in OFFLINE_DATASET_STATES or to_ not in OFFLINE_DATASET_STATES: + raise ValueError( + f"move_datasets(): got states '{from_}', '{to_}", + f" but allowed states are {OFFLINE_DATASET_STATES}", ) - return url = "%s/datasets/%s/move_dataset/%s/%s" % (api_url, workspace, from_, to_) @@ -559,7 +569,7 @@ def move_datasets( payload = json.dumps( {"run_number": run, "dataset_name": dataset_name, "workspace": workspace} ) - return requests.post(url, headers=headers, data=payload) + return [requests.post(url, headers=headers, data=payload)] answers = [] for run_number in runs: diff --git a/tests/test_advanced_rr_operations.py b/tests/test_advanced_rr_operations.py index df32cfa..887f400 100644 --- a/tests/test_advanced_rr_operations.py +++ b/tests/test_advanced_rr_operations.py @@ -3,6 +3,8 @@ import runregistry logger = logging.getLogger(__name__) +VALID_RUN_NUMBER = 362874 +VALID_DATASET_NAME = "/PromptReco/Commissioning2021/DQM" @pytest.fixture @@ -12,27 +14,27 @@ def setup_runregistry(): def test_move_datasets(setup_runregistry): - answer = runregistry.move_datasets( + answers = runregistry.move_datasets( from_=runregistry.WAITING_DQM_GUI_CONSTANT, to_="OPEN", - dataset_name="/PromptReco/Commissioning2021/DQM", - run=362874, + dataset_name=VALID_DATASET_NAME, + run=VALID_RUN_NUMBER, workspace="global", ) # TODO: Run also with a token that has permission - assert answer.status_code == 401 - answer = runregistry.move_datasets( + assert all([answer.status_code == 401 for answer in answers]) + answers = runregistry.move_datasets( from_="OPEN", to_="SIGNOFF", - dataset_name="/PromptReco/Commissioning2021/DQM", - run=362874, + dataset_name=VALID_DATASET_NAME, + run=VALID_RUN_NUMBER, workspace="ctpps", ) # Requires permission - assert answer.status_code == 401 + assert all([answer.status_code == 401 for answer in answers]) -def test_make_significant_runs(setup_runregistry): +def test_make_significant_single_run(setup_runregistry): # Get latest run in dev runregistry and make it significant run = runregistry.get_runs(limit=1, filter={})[0] answer = runregistry.make_significant_runs(run=run["run_number"]) @@ -40,9 +42,16 @@ def test_make_significant_runs(setup_runregistry): assert answer.status_code == 401 +def test_make_significant_multi_runs(setup_runregistry): + # Get latest run in dev runregistry and make it significant + run = runregistry.get_runs(limit=1, filter={})[0] + answers = runregistry.make_significant_runs(runs=[run["run_number"]]) + # requires permission + assert all([answer.status_code == 401 for answer in answers]) + + def test_reset_RR_attributes_and_refresh_runs_signed_off(setup_runregistry): - answers = runregistry.reset_RR_attributes_and_refresh_runs(runs=383843) - print(answers[0].text) + answers = runregistry.reset_RR_attributes_and_refresh_runs(runs=VALID_RUN_NUMBER) # Cannot refresh runs which are not open assert all( [ @@ -67,7 +76,9 @@ def test_reset_RR_attributes_and_refresh_runs_open(setup_runregistry): def test_manually_refresh_components_statuses_for_runs_signed_off(setup_runregistry): - answers = runregistry.manually_refresh_components_statuses_for_runs(runs=383843) + answers = runregistry.manually_refresh_components_statuses_for_runs( + runs=VALID_RUN_NUMBER + ) # Cannot refresh runs which are not open assert all( [ @@ -77,13 +88,35 @@ def test_manually_refresh_components_statuses_for_runs_signed_off(setup_runregis ) -def test_move_runs(setup_runregistry): - answer = runregistry.move_runs("OPEN", "SIGNOFF", run=362761) +def test_move_runs_no_run_arg(setup_runregistry): + with pytest.raises(ValueError): + # Raises ValueError + runregistry.move_runs("OPEN", "SIGNOFF") + + +def test_move_single_run(setup_runregistry): + """ + Unfortunately, this function was given a dual signature, and can return + both a single or a list of request responses. + """ + answer = runregistry.move_runs("OPEN", "SIGNOFF", run=VALID_RUN_NUMBER) # Requires permission assert answer.status_code == 401 +def test_move_multi_runs(setup_runregistry): + """ + Unfortunately, this function was given a dual signature, and can return + both a single or a list of request responses. + """ + answers = runregistry.move_runs("OPEN", "SIGNOFF", runs=[VALID_RUN_NUMBER]) + # Requires permission + assert all([answer.status_code == 401 for answer in answers]) + + def test_edit_rr_lumisections(setup_runregistry): - answer = runregistry.edit_rr_lumisections(380326, 0, 1, "castor-castor", "GOOD") + answer = runregistry.edit_rr_lumisections( + VALID_RUN_NUMBER, 0, 1, "castor-castor", "GOOD" + ) # Requires permission assert answer.status_code == 401 diff --git a/tests/test_client.py b/tests/test_client.py index 7f46e03..93bc5da 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,5 +1,5 @@ -import pytest import json +import warnings from runregistry.runregistry import ( get_run, @@ -10,43 +10,46 @@ get_lumisections, get_oms_lumisections, get_lumisection_ranges, - # get_oms_lumisection_ranges, + get_oms_lumisection_ranges, get_joint_lumisection_ranges, - # generate_json, + generate_json, create_json, setup, ) -common_run_number = 327743 -common_dataset_name = "/PromptReco/HICosmics18A/DQM" +VALID_RUN_NUMBER = 327743 +VALID_RUN_RANGE_START = 309000 +VALID_RUN_RANGE_STOP = 310000 - -def test_with_token(): - run = get_run(run_number=common_run_number) - assert run["run_number"] == common_run_number - lumisections = get_oms_lumisections(run_number=common_run_number) - assert len(lumisections) > 0 +INVALID_RUN_NUMBER = 420420420 +VALID_DATASET_NAME = "/PromptReco/HICosmics18A/DQM" +INVALID_DATASET_NAME = "/PromptKikiriko/HELLOCosmics18Z/DQM" def test_get_run(): - run_number = 328762 - run = get_run(run_number=328762) - # print(run) - assert run["run_number"] == run_number - # Non existent run: - run_number = 8888888888 + run_number = VALID_RUN_NUMBER + run = get_run(run_number=VALID_RUN_NUMBER) + assert run["run_number"] == VALID_RUN_NUMBER + # Non-existent run + run_number = INVALID_RUN_NUMBER run = get_run(run_number=run_number) - assert run == None + assert not run def test_get_runs(): - # Gets runs between run number 309000 and 310000 - filter_run = {"run_number": {"and": [{">": 309000}, {"<": 310000}]}} + # Gets runs between run number VALID_RUN_RANGE_START and VALID_RUN_RANGE_STOP + filter_run = { + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + } + } runs = get_runs(filter=filter_run) assert len(runs) > 0 # Gets runs that contain lumisections that classified DT as GOOD AND lumsiections that classified hcal as STANDBY filter_run = { - "run_number": {"and": [{">": 309000}, {"<": 310000}]}, + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + }, "dt-dt": "GOOD", # 'hcal': 'STANDBY' } @@ -56,7 +59,9 @@ def test_get_runs(): runs = [] filter_run = { - "run_number": {"and": [{">": 309000}, {"<": 310000}]}, + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + }, "tracker-strip": "GOOD", } runs = get_runs(filter=filter_run) @@ -66,7 +71,9 @@ def test_get_runs(): def test_get_runs_with_ignore_filter(): filter_run = { - "run_number": {"and": [{">": 309000}, {"<": 310000}]}, + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + }, "oms_attributes.hlt_key": {"like": "%commissioning2018%"}, "triplet_summary.dt-dt.GOOD": {">": 0}, } @@ -78,9 +85,9 @@ def test_get_datasets_with_ignore_filter(): # datasets = get_datasets(filter={ # "run_number": { # "and": [{ - # ">": 309000 + # ">": VALID_RUN_RANGE_START # }, { - # "<": 310000 + # "<": VALID_RUN_RANGE_STOP # }] # }, # "oms_attributes.hlt_key": { @@ -94,7 +101,16 @@ def test_get_datasets_with_ignore_filter(): datasets = get_datasets( filter={ - "and": [{"run_number": {">": "382000"}}], + "and": [ + { + "run_number": { + "and": [ + {">": VALID_RUN_RANGE_START}, + {"<": VALID_RUN_RANGE_STOP}, + ] + } + } + ], "name": {"and": [{"<>": "online"}]}, "dataset_attributes.global_state": { "and": [{"or": [{"=": "OPEN"}, {"=": "SIGNOFF"}, {"=": "COMPLETED"}]}] @@ -112,7 +128,12 @@ def test_get_datasets_with_ignore_filter(): def test_get_runs_not_compressed(): runs = get_runs( - filter={"run_number": {"and": [{">": 309000}, {"<": 310000}]}, "dt-dt": "GOOD"}, + filter={ + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + }, + "dt-dt": "GOOD", + }, compress_attributes=False, ) assert len(runs) > 0 @@ -122,7 +143,7 @@ def get_runs_with_combined_filter(): runs = get_runs( filter={ "run_number": { - "and": [{">": 309000}, {"<": 310000}] + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] # }, # 'hlt_key': { # 'like': '%commissioning2018%' @@ -136,49 +157,55 @@ def get_runs_with_combined_filter(): def test_get_dataset_names_of_run(): - dataset_names = get_dataset_names_of_run(run_number=321777) + dataset_names = get_dataset_names_of_run(run_number=VALID_RUN_NUMBER) assert len(dataset_names) > 0 def test_get_dataset(): + dataset = get_dataset(run_number=VALID_RUN_NUMBER, dataset_name=VALID_DATASET_NAME) + assert dataset["run_number"] == VALID_RUN_NUMBER + assert dataset["name"] == VALID_DATASET_NAME dataset = get_dataset( - run_number=common_run_number, dataset_name=common_dataset_name + run_number=INVALID_RUN_NUMBER, dataset_name=INVALID_DATASET_NAME ) - assert dataset["run_number"] == common_run_number - assert dataset["name"] == common_dataset_name + assert not dataset def test_get_datasets(): datasets = get_datasets( - filter={"run_number": {"and": [{">": 309000}, {"<": 310000}]}} + filter={ + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + } + } ) assert len(datasets) > 0 def test_get_lumisections(): - lumisections = get_lumisections(common_run_number, common_dataset_name) + lumisections = get_lumisections(VALID_RUN_NUMBER, VALID_DATASET_NAME) assert len(lumisections) > 0 def test_get_oms_lumisections(): - lumisections = get_oms_lumisections(common_run_number) + lumisections = get_oms_lumisections(VALID_RUN_NUMBER) assert len(lumisections) > 0 - dataset_lumisections = get_oms_lumisections(common_run_number, common_dataset_name) + dataset_lumisections = get_oms_lumisections(VALID_RUN_NUMBER, VALID_DATASET_NAME) assert len(dataset_lumisections) > 0 def test_get_lumisection_ranges(): - lumisections = get_lumisection_ranges(common_run_number, common_dataset_name) + lumisections = get_lumisection_ranges(VALID_RUN_NUMBER, VALID_DATASET_NAME) assert len(lumisections) > 0 def test_get_oms_lumisection_ranges(): - lumisections = get_lumisection_ranges(common_run_number, common_dataset_name) + lumisections = get_oms_lumisection_ranges(VALID_RUN_NUMBER) assert len(lumisections) > 0 def test_get_joint_lumisection_ranges(): - lumisections = get_joint_lumisection_ranges(common_run_number, common_dataset_name) + lumisections = get_joint_lumisection_ranges(VALID_RUN_NUMBER, VALID_DATASET_NAME) assert len(lumisections) > 0 @@ -188,19 +215,50 @@ def test_get_collisions18(): def test_get_or_run(): - runs = get_runs(filter={"run_number": {"or": [328762]}}) + runs = get_runs(filter={"run_number": {"or": [VALID_RUN_NUMBER]}}) def test_get_datasets_with_filter(): datasets = get_datasets( filter={ - "run_number": {"and": [{">": 309000}, {"<": 310000}]}, + "run_number": { + "and": [{">": VALID_RUN_RANGE_START}, {"<": VALID_RUN_RANGE_STOP}] + }, "tracker-strip": "GOOD", } ) assert len(datasets) > 0 +def test_generate_json(): + # https://docs.python.org/3/library/warnings.html#testing-warnings + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + generate_json( + """ +{ + "and": [ + { + "or": [ + { + "==": [ + { + "var": "dataset.name" + }, + "/PromptReco/Collisions2018A/DQM" + ] + } + ] + } + ] +} + """ + ) + assert len(w) == 1 + assert issubclass(w[-1].category, PendingDeprecationWarning) + assert "deprecated" in str(w[-1].message) + + # UNSAFE: # def test_generate_json(): # json_logic = """ @@ -335,14 +393,14 @@ def test_create_json(): def test_custom_filter(): filter_arg = { - "dataset_name": {"like": "%/PromptReco/HICollisions2018A%"}, - "run_number": {"and": [{">=": 300000}, {"<=": 330000}]}, - "class": {"like": "Collisions18"}, + "dataset_name": {"like": "%/PromptReco/Cosmics18CRUZET%"}, + "run_number": { + "and": [{">=": VALID_RUN_RANGE_START}, {"<=": VALID_RUN_RANGE_STOP}] + }, + "class": {"like": "Cosmics18CRUZET"}, "global_state": {"like": "COMPLETED"}, - "ecal-ecal": "BAD", + "ecal-ecal": "EXCLUDED", } datasets = get_datasets(filter=filter_arg) - - -# test_custom_filter() + assert datasets