# Path: socceraction/data/base.py
# class ParseError(Exception):
#     """Exception raised when a file is not correctly formatted."""
# 
# Path: socceraction/data/statsbomb/schema.py
# class StatsBombCompetitionSchema(CompetitionSchema):
#     """Definition of a dataframe containing a list of competitions and seasons."""
# 
#     country_name: Series[str]
#     """The name of the country the competition relates to."""
#     competition_gender: Series[str]
#     """The gender of the players competing in the competition."""
# 
# class StatsBombEventSchema(EventSchema):
#     """Definition of a dataframe containing event stream data of a game."""
# 
#     index: Series[int]
#     """Sequence notation for the ordering of events within each match."""
#     timestamp: Series[DateTime]
#     """Time in the match the event takes place, recorded to the millisecond."""
#     minute: Series[int]
#     """The minutes on the clock at the time of this event."""
#     second: Series[int] = pa.Field(ge=0, le=59)
#     """The second part of the timestamp."""
#     possession: Series[int]
#     """Indicates the current unique possession in the game."""
#     possession_team_id: Series[int]
#     """The ID of the team that started this possession in control of the ball."""
#     possession_team_name: Series[str]
#     """The name of the team that started this possession in control of the ball."""
#     play_pattern_id: Series[int]
#     """The ID of the play pattern relevant to this event."""
#     play_pattern_name: Series[str]
#     """The name of the play pattern relevant to this event."""
#     team_name: Series[str]
#     """The name of the team this event relates to."""
#     duration: Series[float] = pa.Field(nullable=True)
#     """If relevant, the length in seconds the event lasted."""
#     extra: Series[Object]
#     """A JSON string containing type-specific information."""
#     related_events: Series[Object]
#     """A comma separated list of the IDs of related events."""
#     player_name: Series[str] = pa.Field(nullable=True)
#     """The name of the player this event relates to."""
#     position_id: Series[float] = pa.Field(nullable=True)
#     """The ID of the position the player was in at the time of this event."""
#     position_name: Series[str] = pa.Field(nullable=True)
#     """The name of the position the player was in at the time of this event."""
#     location: Series[Object] = pa.Field(nullable=True)
#     """Array containing the x and y coordinates of the event."""
#     under_pressure: Series[bool] = pa.Field(nullable=True)
#     """Whether the action was performed while being pressured by an opponent."""
#     counterpress: Series[bool] = pa.Field(nullable=True)
#     """Pressing actions within 5 seconds of an open play turnover."""
#     visible_area_360: Optional[Series[Object]] = pa.Field(nullable=True)
#     """An array of coordinates describing the polygon visible to the camera / in the 360 frame."""
#     freeze_frame_360: Optional[Series[Object]] = pa.Field(nullable=True)
#     """An array of freeze frame objects."""
# 
# class StatsBombGameSchema(GameSchema):
#     """Definition of a dataframe containing a list of games."""
# 
#     competition_stage: Series[str]
#     """The name of the phase of the competition this game is in."""
#     home_score: Series[int]
#     """The final score of the home team."""
#     away_score: Series[int]
#     """The final score of the away team."""
#     venue: Series[str] = pa.Field(nullable=True)
#     """The name of the stadium where the game was played."""
#     referee: Series[str] = pa.Field(nullable=True)
#     """The name of the referee."""
# 
# class StatsBombPlayerSchema(PlayerSchema):
#     """Definition of a dataframe containing the list of players of a game."""
# 
#     nickname: Series[str] = pa.Field(nullable=True)
#     """The nickname of the player on the team."""
#     starting_position_id: Series[int]
#     """The unique identifier for the starting position of the player on the team."""
#     starting_position_name: Series[str]
#     """The name of the starting position of the player on the team."""
# 
# class StatsBombTeamSchema(TeamSchema):
#     """Definition of a dataframe containing the list of teams of a game."""


import json
import os
import shutil
import sys
import unittest
import pytest
import socceraction.data.statsbomb as sb
from importlib import reload
from py.path import local
from pytest import fixture
from socceraction.data.base import ParseError
from socceraction.data.statsbomb import (
    StatsBombCompetitionSchema,
    StatsBombEventSchema,
    StatsBombGameSchema,
    StatsBombPlayerSchema,
    StatsBombTeamSchema,
)
        sys.modules["statsbombpy"] = None  # type: ignore
        reload(sys.modules["socceraction.data.statsbomb.loader"])

    def tearDown(self) -> None:
        sys.modules["statsbombpy"] = self._temp_sbpy  # type: ignore
        reload(sys.modules["socceraction.data.statsbomb.loader"])

    def tests_load_without_statsbombpy(self) -> None:
        """It raises an error upon initialization of a remote loader if statsbombpy is not installed."""
        with pytest.raises(ImportError):
            sb.StatsBombLoader(getter="remote")


# Test competitions ##########################################################


def test_competitions(SBL: sb.StatsBombLoader) -> None:
    """It loads a DataFrame with available competitions."""
    df_competitions = SBL.competitions()
    assert len(df_competitions) > 0
    StatsBombCompetitionSchema.validate(df_competitions)


def test_no_competitions(tmpdir: local) -> None:
    """It returns an empty DataFrame when no competitions are available."""
    p = tmpdir.join("competitions.json")
    p.write(json.dumps([]))
    SBL = sb.StatsBombLoader(root=str(tmpdir), getter="local")
    df_competitions = SBL.competitions()
    assert len(df_competitions) == 0

# Path: socceraction/data/base.py
# class ParseError(Exception):
#     """Exception raised when a file is not correctly formatted."""
# 
# Path: socceraction/data/statsbomb/schema.py
# class StatsBombCompetitionSchema(CompetitionSchema):
#     """Definition of a dataframe containing a list of competitions and seasons."""
# 
#     country_name: Series[str]
#     """The name of the country the competition relates to."""
#     competition_gender: Series[str]
#     """The gender of the players competing in the competition."""
# 
# class StatsBombEventSchema(EventSchema):
#     """Definition of a dataframe containing event stream data of a game."""
# 
#     index: Series[int]
#     """Sequence notation for the ordering of events within each match."""
#     timestamp: Series[DateTime]
#     """Time in the match the event takes place, recorded to the millisecond."""
#     minute: Series[int]
#     """The minutes on the clock at the time of this event."""
#     second: Series[int] = pa.Field(ge=0, le=59)
#     """The second part of the timestamp."""
#     possession: Series[int]
#     """Indicates the current unique possession in the game."""
#     possession_team_id: Series[int]
#     """The ID of the team that started this possession in control of the ball."""
#     possession_team_name: Series[str]
#     """The name of the team that started this possession in control of the ball."""
#     play_pattern_id: Series[int]
#     """The ID of the play pattern relevant to this event."""
#     play_pattern_name: Series[str]
#     """The name of the play pattern relevant to this event."""
#     team_name: Series[str]
#     """The name of the team this event relates to."""
#     duration: Series[float] = pa.Field(nullable=True)
#     """If relevant, the length in seconds the event lasted."""
#     extra: Series[Object]
#     """A JSON string containing type-specific information."""
#     related_events: Series[Object]
#     """A comma separated list of the IDs of related events."""
#     player_name: Series[str] = pa.Field(nullable=True)
#     """The name of the player this event relates to."""
#     position_id: Series[float] = pa.Field(nullable=True)
#     """The ID of the position the player was in at the time of this event."""
#     position_name: Series[str] = pa.Field(nullable=True)
#     """The name of the position the player was in at the time of this event."""
#     location: Series[Object] = pa.Field(nullable=True)
#     """Array containing the x and y coordinates of the event."""
#     under_pressure: Series[bool] = pa.Field(nullable=True)
#     """Whether the action was performed while being pressured by an opponent."""
#     counterpress: Series[bool] = pa.Field(nullable=True)
#     """Pressing actions within 5 seconds of an open play turnover."""
#     visible_area_360: Optional[Series[Object]] = pa.Field(nullable=True)
#     """An array of coordinates describing the polygon visible to the camera / in the 360 frame."""
#     freeze_frame_360: Optional[Series[Object]] = pa.Field(nullable=True)
#     """An array of freeze frame objects."""
# 
# class StatsBombGameSchema(GameSchema):
#     """Definition of a dataframe containing a list of games."""
# 
#     competition_stage: Series[str]
#     """The name of the phase of the competition this game is in."""
#     home_score: Series[int]
#     """The final score of the home team."""
#     away_score: Series[int]
#     """The final score of the away team."""
#     venue: Series[str] = pa.Field(nullable=True)
#     """The name of the stadium where the game was played."""
#     referee: Series[str] = pa.Field(nullable=True)
#     """The name of the referee."""
# 
# class StatsBombPlayerSchema(PlayerSchema):
#     """Definition of a dataframe containing the list of players of a game."""
# 
#     nickname: Series[str] = pa.Field(nullable=True)
#     """The nickname of the player on the team."""
#     starting_position_id: Series[int]
#     """The unique identifier for the starting position of the player on the team."""
#     starting_position_name: Series[str]
#     """The name of the starting position of the player on the team."""
# 
# class StatsBombTeamSchema(TeamSchema):
#     """Definition of a dataframe containing the list of teams of a game."""


# Path: tests/data/test_load_statsbomb.py
import json
import os
import shutil
import sys
import unittest
import pytest
import socceraction.data.statsbomb as sb
from importlib import reload
from py.path import local
from pytest import fixture
from socceraction.data.base import ParseError
from socceraction.data.statsbomb import (
    StatsBombCompetitionSchema,
    StatsBombEventSchema,
    StatsBombGameSchema,
    StatsBombPlayerSchema,
    StatsBombTeamSchema,
)

        sys.modules["statsbombpy"] = None  # type: ignore
        reload(sys.modules["socceraction.data.statsbomb.loader"])

    def tearDown(self) -> None:
        sys.modules["statsbombpy"] = self._temp_sbpy  # type: ignore
        reload(sys.modules["socceraction.data.statsbomb.loader"])

    def tests_load_without_statsbombpy(self) -> None:
        """It raises an error upon initialization of a remote loader if statsbombpy is not installed."""
        with pytest.raises(ImportError):
            sb.StatsBombLoader(getter="remote")


# Test competitions ##########################################################


def test_competitions(SBL: sb.StatsBombLoader) -> None:
    """It loads a DataFrame with available competitions."""
    df_competitions = SBL.competitions()
    assert len(df_competitions) > 0
    StatsBombCompetitionSchema.validate(df_competitions)


def test_no_competitions(tmpdir: local) -> None:
    """It returns an empty DataFrame when no competitions are available."""
    p = tmpdir.join("competitions.json")
    p.write(json.dumps([]))
    SBL = sb.StatsBombLoader(root=str(tmpdir), getter="local")
    df_competitions = SBL.competitions()
    assert len(df_competitions) == 0

    StatsBombCompetitionSchema.validate(df_competitions)