<commit_before># -*- coding: utf-8 -*-
"""Test for the execution scheduler"""

import os

import simplejson as json

from ..processing_controller_client import ProcessingControllerDbClient


# class DbClientTests(unittest.TestCase):
#     def setUp(self):
#         self._db = ProcessingControllerClient()
#         self._log = logging.getLogger("DbClientTests.testPath")
#
#     def tearDown(self):
#         """Executed after each test."""

# if __name__ == '__main__':
#     # Deletes all the data in the database
#     r = redis.Redis()
#     r.flushdb()
#
#     # Populates the database with initial data
#     os.system("python3 -m utils.set_initial_data")
#
#     logging.basicConfig(stream=sys.stderr)
#     logging.getLogger("DbClientTests.testPath").setLevel(logging.DEBUG)
#     unittest.main()


def test_events(db_client):
    """Test Scheduling Block Instance and Processing Block events."""
    print("Get Scheduling block Event")
    event_block = "scheduling_block"
    event = db_client.get_latest_event(event_block)
    print(event)

    print("Get Processing Block Event")
    processing_block = "processing_block"
    event = db_client.get_latest_event(processing_block)
    print(event)


def test_get_block_details(db_client):
    """Test returning details of a SBI or PB"""
    print("Get Scheduling block")
    block_id = ["20180201-test-sbi000"]
    scheduling_block_instance = db_client.get_block_details(block_id)
    for instance in scheduling_block_instance:
        print(instance)

    print("Get Scheduling block which has no processing block")
    block_id = ["20180201-test-sbi001"]
    scheduling_block_instance = db_client.get_block_details(block_id)
    for instance in scheduling_block_instance:
        print(instance)

    print("Get processing block")
    p_blk_ids = ["sip-vis000", "sip-vis001", "sip-vis001"]
    block_ids = db_client.get_processing_block_ids()
    _blocks = [b for b in db_client.get_block_details(p_blk_ids, sort=True)]
    print(_blocks)
    assert len(block_ids) == len(_blocks)

    print("Get scheduling block and processing blocks")
    processing_block_id = ["20180201-test-sbi000", "sip-vis000", "sip-vis001"]
    processing_blocks = db_client.get_block_details(processing_block_id)
    for blocks in processing_blocks:
        print(blocks)


def test_get_ids(db_client):
    """Test asking for various ids (PB, SBI, Subarray) from the db."""
    print("Get number of scheduling block ids")
    num_blocks = db_client.get_num_scheduling_block_ids()
    print(num_blocks)

    print("Get number of processing block ids")
    num_blocks = db_client.get_num_processing_block_ids()
    print(num_blocks)

    print("Get scheduling block ids")
    for _id in db_client.get_sched_block_instance_ids():
        print(_id)

    print("Get processing block ids")
    for _id in db_client.get_processing_block_ids():
        print(_id)

    print("Get sub array ids")
    for _id in db_client.get_sub_array_ids():
        print(_id)

    print("Get scheduling block id using sub array id")
    sub_array_id = 'subarray000'
    _id = db_client.get_sub_array_sbi_ids(sub_array_id)
    print(_id)


def main():
    """."""
    db_client = ProcessingControllerDbClient()

    print("***Test Configuration Db client for the Processing Controller***")

    file_path = os.path.dirname(__file__)
    config_path = os.path.join(file_path, '..', 'utils',
                               'scheduling_block_data.json')
    with open(config_path, 'r') as file:
        block_data = file.read()<commit_msg>reverted to version from master<commit_after># -*- coding: utf-8 -*-
"""Test for the execution scheduler"""

import os

import simplejson as json

from ..processing_controller_client import ProcessingControllerDbClient


# class DbClientTests(unittest.TestCase):
#     def setUp(self):
#         self._db = ProcessingControllerClient()
#         self._log = logging.getLogger("DbClientTests.testPath")
#
#     def tearDown(self):
#         """Executed after each test."""

# if __name__ == '__main__':
#     # Deletes all the data in the database
#     r = redis.Redis()
#     r.flushdb()
#
#     # Populates the database with initial data
#     os.system("python3 -m utils.set_initial_data")
#
#     logging.basicConfig(stream=sys.stderr)
#     logging.getLogger("DbClientTests.testPath").setLevel(logging.DEBUG)
#     unittest.main()


def test_events(db_client):
    """Test Scheduling Block Instance and Processing Block events."""
    print("Get Scheduling block Event")
    event_block = "scheduling_block"
    event = db_client.get_latest_event(event_block)
    print(event)

    print("Get Processing Block Event")
    processing_block = "processing_block"
    event = db_client.get_latest_event(processing_block)
    print(event)


def test_get_block_details(db_client):
    """Test returning details of a SBI or PB"""
    print("Get Scheduling block")
    block_id = ["20180201-test-sbi000"]
    scheduling_block_instance = db_client.get_block_details(block_id)
    for instance in scheduling_block_instance:
        print(instance)

    print("Get Scheduling block which has no processing block")
    block_id = ["20180201-test-sbi001"]
    scheduling_block_instance = db_client.get_block_details(block_id)
    for instance in scheduling_block_instance:
        print(instance)

    print("Get processing block")
    p_blk_ids = ["sip-vis000", "sip-vis001", "sip-vis001"]
    block_ids = db_client.get_processing_block_ids()
    _blocks = [b for b in db_client.get_block_details(p_blk_ids, sort=True)]
    print(_blocks)
    assert len(block_ids) == len(_blocks)

    print("Get scheduling block and processing blocks")
    processing_block_id = ["20180201-test-sbi000", "sip-vis000", "sip-vis001"]
    processing_blocks = db_client.get_block_details(processing_block_id)
    for blocks in processing_blocks:
        print(blocks)


def test_get_ids(db_client):
    """Test asking for various ids (PB, SBI, Subarray) from the db."""
    print("Get number of scheduling block ids")
    num_blocks = db_client.get_num_scheduling_block_ids()
    print(num_blocks)

    print("Get number of processing block ids")
    num_blocks = db_client.get_num_processing_block_ids()
    print(num_blocks)

    print("Get scheduling block ids")
    for _id in db_client.get_scheduling_block_ids():
        print(_id)

    print("Get processing block ids")
    for _id in db_client.get_processing_block_ids():
        print(_id)

    print("Get sub array ids")
    for _id in db_client.get_sub_array_ids():
        print(_id)

    print("Get scheduling block id using sub array id")
    sub_array_id = 'subarray000'
    _id = db_client.get_sub_array_sbi_ids(sub_array_id)
    print(_id)


def main():
    """."""
    db_client = ProcessingControllerDbClient()

    print("***Test Configuration Db client for the Processing Controller***")

    file_path = os.path.dirname(__file__)
    config_path = os.path.join(file_path, '..', 'utils',
                               'scheduling_block_data.json')
    with open(config_path, 'r') as file:
        block_data = file.read()
{'fraction_non_alphanumeric': 0.10758426966292135, 'fraction_numerical': 0.014887640449438203, 'mean_word_length': 3.7568470273881096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6208108', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2190, 'n_words': 517}