from __future__ import annotations

import gc
import os
import time
from typing import Optional, Union

import pytest
import supervision as sv
from inference.core.workflows.core_steps.sinks.roboflow.dataset_upload.v1 import \
    is_prediction_registration_forbidden


def codeflash_wrap(codeflash_wrapped, codeflash_test_module_name, codeflash_test_class_name, codeflash_test_name, codeflash_function_name, codeflash_line_id, codeflash_loop_index, *args, **kwargs):
    test_id = f'{codeflash_test_module_name}:{codeflash_test_class_name}:{codeflash_test_name}:{codeflash_line_id}:{codeflash_loop_index}'
    if not hasattr(codeflash_wrap, 'index'):
        codeflash_wrap.index = {}
    if test_id in codeflash_wrap.index:
        codeflash_wrap.index[test_id] += 1
    else:
        codeflash_wrap.index[test_id] = 0
    codeflash_test_index = codeflash_wrap.index[test_id]
    invocation_id = f'{codeflash_line_id}_{codeflash_test_index}'
    test_stdout_tag = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_loop_index}:{invocation_id}"
    print(f'!$######{test_stdout_tag}######$!')
    exception = None
    gc.disable()
    try:
        counter = time.perf_counter_ns()
        return_value = codeflash_wrapped(*args, **kwargs)
        codeflash_duration = time.perf_counter_ns() - counter
    except Exception as e:
        codeflash_duration = time.perf_counter_ns() - counter
        exception = e
    gc.enable()
    print(f'!######{test_stdout_tag}:{codeflash_duration}######!')
    if exception:
        raise exception
    return return_value

class TestIsPredicationRegistrationForbiddenBasic:
    """Basic tests for normal conditions with typical inputs."""

    def test_none_prediction_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is None, function should return True.'
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_none_prediction_returns_true', 'is_prediction_registration_forbidden', '1', codeflash_loop_index, None)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_empty_detections_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is empty Detections object, function should return True.'
        empty_detections = sv.Detections.empty()
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_empty_detections_returns_true', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, empty_detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_top_key_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key, function should return False."
        prediction = {'top': [1, 2, 3]}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_dict_with_top_key_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_predicted_classes_key_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'predicted_classes' key, function should return False."
        prediction = {'predicted_classes': ['cat', 'dog']}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_dict_with_predicted_classes_key_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_both_keys_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with both 'top' and 'predicted_classes' keys, function should return False."
        prediction = {'top': [1, 2], 'predicted_classes': ['cat']}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_dict_with_both_keys_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_empty_dict_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is empty dict, function should return True.'
        prediction = {}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_empty_dict_returns_true', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_other_keys_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with only other keys (not 'top' or 'predicted_classes'), function should return True."
        prediction = {'other_key': 'value'}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_dict_with_other_keys_returns_true', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_nonempty_detections_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is non-empty Detections object, function should return False.'
        xyxy = [[10, 20, 100, 200]]
        class_id = [0]
        detections = sv.Detections(xyxy=xyxy, class_id=class_id)
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenBasic', 'test_nonempty_detections_returns_false', 'is_prediction_registration_forbidden', '4', codeflash_loop_index, detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

class TestIsPredicationRegistrationForbiddenEdge:
    """Edge tests for extreme or unusual conditions."""

    def test_dict_with_top_key_empty_value_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key but empty value, function should return False."
        prediction = {'top': []}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_top_key_empty_value_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_predicted_classes_empty_value_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'predicted_classes' key but empty value, function should return False."
        prediction = {'predicted_classes': []}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_predicted_classes_empty_value_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_top_key_none_value_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key and None value, function should return False."
        prediction = {'top': None}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_top_key_none_value_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_top_and_other_keys_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key and other unrelated keys, function should return False."
        prediction = {'top': [1], 'random_key': 'value', 'another_key': 123}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_top_and_other_keys_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_predicted_classes_and_other_keys_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'predicted_classes' key and other unrelated keys, function should return False."
        prediction = {'predicted_classes': ['a'], 'random': 'data'}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_predicted_classes_and_other_keys_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_case_sensitive_top_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'Top' (uppercase), should return True since key is case-sensitive."
        prediction = {'Top': [1, 2, 3]}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_case_sensitive_top_returns_true', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_case_sensitive_predicted_classes_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'Predicted_Classes' (mixed case), should return True since key is case-sensitive."
        prediction = {'Predicted_Classes': ['cat']}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_case_sensitive_predicted_classes_returns_true', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_numeric_values_for_top_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key and numeric values, function should return False."
        prediction = {'top': 42}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_numeric_values_for_top_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_string_values_for_predicted_classes_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'predicted_classes' key and string values, function should return False."
        prediction = {'predicted_classes': 'class1'}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_string_values_for_predicted_classes_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_nested_structure_for_top_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key and nested dict value, function should return False."
        prediction = {'top': {'nested': 'value'}}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_dict_with_nested_structure_for_top_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_detections_with_single_detection_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is Detections object with single detection, function should return False.'
        xyxy = [[50, 50, 150, 150]]
        detections = sv.Detections(xyxy=xyxy)
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_detections_with_single_detection_returns_false', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_detections_with_zero_area_detection_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is Detections object with zero-area detection, function should return False (length is 1).'
        xyxy = [[100, 100, 100, 100]]
        detections = sv.Detections(xyxy=xyxy)
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenEdge', 'test_detections_with_zero_area_detection_returns_false', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

class TestIsPredicationRegistrationForbiddenLargeScale:
    """Large-scale tests for performance and scalability."""

    def test_dict_with_many_keys_containing_top_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with many keys including 'top', function should return False."
        prediction = {f'key_{i}': i for i in range(100)}
        prediction['top'] = [1, 2, 3]
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_dict_with_many_keys_containing_top_returns_false', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_many_keys_containing_predicted_classes_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with many keys including 'predicted_classes', function should return False."
        prediction = {f'key_{i}': i for i in range(100)}
        prediction['predicted_classes'] = ['a', 'b']
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_dict_with_many_keys_containing_predicted_classes_returns_false', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_many_keys_but_no_required_keys_returns_true(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with many keys but no 'top' or 'predicted_classes', function should return True."
        prediction = {f'key_{i}': i for i in range(100)}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_dict_with_many_keys_but_no_required_keys_returns_true', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_detections_with_many_detections_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is Detections object with many detections, function should return False.'
        xyxy = [[i, i, i + 50, i + 50] for i in range(100)]
        detections = sv.Detections(xyxy=xyxy)
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_detections_with_many_detections_returns_false', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_large_values_in_top_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'top' key and large value list, function should return False."
        prediction = {'top': list(range(1000))}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_dict_with_large_values_in_top_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_dict_with_large_values_in_predicted_classes_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "When prediction is dict with 'predicted_classes' key and large value list, function should return False."
        prediction = {'predicted_classes': [f'class_{i}' for i in range(1000)]}
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_dict_with_large_values_in_predicted_classes_returns_false', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, prediction)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_detections_with_very_large_count_returns_false(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'When prediction is Detections object with 500 detections, function should return False.'
        xyxy = [[i * 2, i * 2, i * 2 + 50, i * 2 + 50] for i in range(500)]
        detections = sv.Detections(xyxy=xyxy)
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenLargeScale', 'test_detections_with_very_large_count_returns_false', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

class TestIsPredicationRegistrationForbiddenReturnType:
    """Tests verifying the return type is always boolean."""

    def test_return_type_is_bool_for_none(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'Return type should be bool for None input.'
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenReturnType', 'test_return_type_is_bool_for_none', 'is_prediction_registration_forbidden', '1', codeflash_loop_index, None)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_return_type_is_bool_for_empty_detections(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'Return type should be bool for empty Detections.'
        empty_detections = sv.Detections.empty()
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenReturnType', 'test_return_type_is_bool_for_empty_detections', 'is_prediction_registration_forbidden', '2', codeflash_loop_index, empty_detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_return_type_is_bool_for_dict_with_top(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        "Return type should be bool for dict with 'top' key."
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenReturnType', 'test_return_type_is_bool_for_dict_with_top', 'is_prediction_registration_forbidden', '1', codeflash_loop_index, {'top': [1]})
        codeflash_output = codeflash_return_value
        result = codeflash_output

    def test_return_type_is_bool_for_nonempty_detections(self):
        codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
        'Return type should be bool for non-empty Detections.'
        xyxy = [[0, 0, 100, 100]]
        detections = sv.Detections(xyxy=xyxy)
        codeflash_return_value = codeflash_wrap(is_prediction_registration_forbidden, 'tests.inference.unit_tests.test_is_prediction_registration_forbidden__unit_test_1', 'TestIsPredicationRegistrationForbiddenReturnType', 'test_return_type_is_bool_for_nonempty_detections', 'is_prediction_registration_forbidden', '3', codeflash_loop_index, detections)
        codeflash_output = codeflash_return_value
        result = codeflash_output