# Path: pytablereader/error.py
# class InvalidFilePathError(PathError):
#     """
#     Exception raised when invalid file path used.
# 
#     TODO: rename the error class
#     """
# 
# Path: pytablereader/_common.py
# def get_extension(file_path):
#     if typepy.is_null_string(file_path):
#         raise InvalidFilePathError("file path is empty")
# 
#     return os.path.splitext(file_path)[1].lstrip(".")
# 
# def make_temp_file_path_from_url(temp_dir_path, url):
#     try:
#         url_path = urlparse(url).path
#     except AttributeError:
#         raise InvalidFilePathError("url must be a string")
# 
#     if typepy.is_null_string(url_path):
#         raise InvalidFilePathError(f"invalid URL path: {url_path}")
# 
#     temp_name = os.path.basename(url_path.rstrip("/"))
#     if typepy.is_null_string(temp_name):
#         temp_name = pathvalidate.replace_symbol(temp_name, replacement_text="_")
# 
#     if typepy.is_null_string(temp_name):
#         raise InvalidFilePathError(f"invalid URL: {url}")
# 
#     try:
#         return posixpath.join(temp_dir_path, temp_name)
#     except (TypeError, AttributeError):
#         raise InvalidFilePathError("temp_dir_path must be a string")


import pytest
from pytablereader import InvalidFilePathError
from pytablereader._common import get_extension, make_temp_file_path_from_url

class Test_make_temp_file_path_from_url:
    @pytest.mark.parametrize(
        ["temp_dir_path", "value", "expected"],
        [
            [
                "/tmp",
                "https://raw.githubusercontent.com/valid/test/data/validext.csv",
                "/tmp/validext.csv",
            ],
            [
                "/tmp",
                "https://raw.githubusercontent.com/valid/test/data/validext/",
                "/tmp/validext",
            ],
        ],
    )
    def test_normal(self, temp_dir_path, value, expected):
        assert make_temp_file_path_from_url(temp_dir_path, value) == expected

    @pytest.mark.parametrize(
        ["temp_dir_path", "value", "expected"],
        [
            [None, "tmp", InvalidFilePathError],
            ["tmp", "", InvalidFilePathError],
            ["tmp", None, InvalidFilePathError],
        ],
    )
    def test_null_table_name(self, temp_dir_path, value, expected):
        with pytest.raises(expected):

# Path: pytablereader/error.py
# class InvalidFilePathError(PathError):
#     """
#     Exception raised when invalid file path used.
# 
#     TODO: rename the error class
#     """
# 
# Path: pytablereader/_common.py
# def get_extension(file_path):
#     if typepy.is_null_string(file_path):
#         raise InvalidFilePathError("file path is empty")
# 
#     return os.path.splitext(file_path)[1].lstrip(".")
# 
# def make_temp_file_path_from_url(temp_dir_path, url):
#     try:
#         url_path = urlparse(url).path
#     except AttributeError:
#         raise InvalidFilePathError("url must be a string")
# 
#     if typepy.is_null_string(url_path):
#         raise InvalidFilePathError(f"invalid URL path: {url_path}")
# 
#     temp_name = os.path.basename(url_path.rstrip("/"))
#     if typepy.is_null_string(temp_name):
#         temp_name = pathvalidate.replace_symbol(temp_name, replacement_text="_")
# 
#     if typepy.is_null_string(temp_name):
#         raise InvalidFilePathError(f"invalid URL: {url}")
# 
#     try:
#         return posixpath.join(temp_dir_path, temp_name)
#     except (TypeError, AttributeError):
#         raise InvalidFilePathError("temp_dir_path must be a string")


# Path: test/test_common.py
import pytest
from pytablereader import InvalidFilePathError
from pytablereader._common import get_extension, make_temp_file_path_from_url


class Test_make_temp_file_path_from_url:
    @pytest.mark.parametrize(
        ["temp_dir_path", "value", "expected"],
        [
            [
                "/tmp",
                "https://raw.githubusercontent.com/valid/test/data/validext.csv",
                "/tmp/validext.csv",
            ],
            [
                "/tmp",
                "https://raw.githubusercontent.com/valid/test/data/validext/",
                "/tmp/validext",
            ],
        ],
    )
    def test_normal(self, temp_dir_path, value, expected):
        assert make_temp_file_path_from_url(temp_dir_path, value) == expected

    @pytest.mark.parametrize(
        ["temp_dir_path", "value", "expected"],
        [
            [None, "tmp", InvalidFilePathError],
            ["tmp", "", InvalidFilePathError],
            ["tmp", None, InvalidFilePathError],
        ],
    )
    def test_null_table_name(self, temp_dir_path, value, expected):
        with pytest.raises(expected):

            make_temp_file_path_from_url(temp_dir_path, value)