# Path: approvaltests/approval_exception.py
# class FrameNotFound(ApprovalException):
#     pass


import inspect
import json
import os
from inspect import FrameInfo
from typing import Dict, List, Optional
from approvaltests.approval_exception import FrameNotFound

    def __init__(self, extension: Optional[str] = None) -> None:
        Namer.__init__(self, extension)
        self.set_for_stack(inspect.stack(1))
        self.config: Dict[str, str] = {}
        self.config_loaded = False

    def set_for_stack(self, caller: List[FrameInfo]) -> None:
        frame = self.get_test_frame(caller)
        stacktrace = caller[frame]
        self.MethodName = stacktrace[3]
        self.ClassName = self.get_class_name_for_frame(stacktrace)
        self.Directory = os.path.dirname(stacktrace[1])

    def get_class_name_for_frame(self, stacktrace: FrameInfo) -> str:
        if "self" not in stacktrace[0].f_locals:
            return os.path.splitext(os.path.basename(stacktrace[1]))[0]
        else:
            return f"{stacktrace[0].f_locals['self'].__class__.__name__}"

    def get_test_frame(self, caller: List[FrameInfo]) -> int:
        tmp_array = []
        for index, frame in enumerate(caller):
            if self.is_test_method(frame):
                tmp_array.append(index)
        if tmp_array:
            return tmp_array[-1]
        message = """Could not find test method/function. Possible reasons could be: 
1) approvaltests is not being used inside a test function 
2) your test framework is not supported by ApprovalTests (unittest and pytest are currently supported)."""

# Path: approvaltests/approval_exception.py
# class FrameNotFound(ApprovalException):
#     pass


# Path: approvaltests/core/namer.py
import inspect
import json
import os
from inspect import FrameInfo
from typing import Dict, List, Optional
from approvaltests.approval_exception import FrameNotFound


    def __init__(self, extension: Optional[str] = None) -> None:
        Namer.__init__(self, extension)
        self.set_for_stack(inspect.stack(1))
        self.config: Dict[str, str] = {}
        self.config_loaded = False

    def set_for_stack(self, caller: List[FrameInfo]) -> None:
        frame = self.get_test_frame(caller)
        stacktrace = caller[frame]
        self.MethodName = stacktrace[3]
        self.ClassName = self.get_class_name_for_frame(stacktrace)
        self.Directory = os.path.dirname(stacktrace[1])

    def get_class_name_for_frame(self, stacktrace: FrameInfo) -> str:
        if "self" not in stacktrace[0].f_locals:
            return os.path.splitext(os.path.basename(stacktrace[1]))[0]
        else:
            return f"{stacktrace[0].f_locals['self'].__class__.__name__}"

    def get_test_frame(self, caller: List[FrameInfo]) -> int:
        tmp_array = []
        for index, frame in enumerate(caller):
            if self.is_test_method(frame):
                tmp_array.append(index)
        if tmp_array:
            return tmp_array[-1]
        message = """Could not find test method/function. Possible reasons could be: 
1) approvaltests is not being used inside a test function 
2) your test framework is not supported by ApprovalTests (unittest and pytest are currently supported)."""

        raise FrameNotFound(message)