<commit_before>import os.path

import pytest
import requests

from pgpy.fileloader import FileLoader

try:
    e = FileNotFoundError
except NameError:
    e = IOError

skipurls = False
try:
    test_request = requests.get("https://www.google.com/robots.txt")
except ConnectionError:
    skipurls = True


@pytest.fixture(
    params=[
        None,
        pytest.mark.skipif(skipurls, "http://www.dancewithgrenades.com/robots.txt", reason="No Internet"),
        pytest.mark.skipif(skipurls, "https://www.google.com/robots.txt", reason="No Internet"),
        "tests/testdata/unsigned_message",
        "tests/testdata/sym_to_unsigned_message",
        open("tests/testdata/unsigned_message", 'rb'),
        open("tests/testdata/unsigned_message", 'rb').read(),
        open("tests/testdata/testkeys.gpg", 'rb').read(),
        "tests/testdata/newfile",
    ],
    ids=[
        "None",
        "http",
        "https",
        "path",
        "symlink",
        "fileobj",
        "unsigned-text-bytes",
        "gpg-keyring-bytes",
        "newfile",
    ]
)
def load(request):
    return request.param


class TestFileLoader:
    def test_load(self, load, request):
        f = FileLoader(load)

        if request.node._genid in ['path', 'symlink', 'newfile']:
            assert f.path == os.path.realpath(load)

        elif request.node._genid == 'fileobj':
            assert f.path == os.path.realpath(load.name)

        else:
            assert f.path is None

    @pytest.mark.parametrize("fload", ["/this/path/is/not/valid", "http://www.google.com/404"],
                             ids=["invalid-path", "invalid-url"])
    def test_load_fail(self, fload):
        with pytest.raises(e):
            FileLoader(fload)<commit_msg> - fixed an exception clause to use the proper path to that exception  - added a skipif to test_load_fail invalid-url<commit_after>import os.path

import pytest
import requests

from pgpy.fileloader import FileLoader

try:
    e = FileNotFoundError
except NameError:
    e = IOError

skipurls = False
try:
    test_request = requests.get("https://www.google.com/robots.txt")
except requests.exceptions.ConnectionError:
    skipurls = True


@pytest.fixture(
    params=[
        None,
        pytest.mark.skipif(skipurls, "http://www.dancewithgrenades.com/robots.txt", reason="No Internet"),
        pytest.mark.skipif(skipurls, "https://www.google.com/robots.txt", reason="No Internet"),
        "tests/testdata/unsigned_message",
        "tests/testdata/sym_to_unsigned_message",
        open("tests/testdata/unsigned_message", 'rb'),
        open("tests/testdata/unsigned_message", 'rb').read(),
        open("tests/testdata/testkeys.gpg", 'rb').read(),
        "tests/testdata/newfile",
    ],
    ids=[
        "None",
        "http",
        "https",
        "path",
        "symlink",
        "fileobj",
        "unsigned-text-bytes",
        "gpg-keyring-bytes",
        "newfile",
    ]
)
def load(request):
    return request.param


class TestFileLoader:
    def test_load(self, load, request):
        f = FileLoader(load)

        if request.node._genid in ['path', 'symlink', 'newfile']:
            assert f.path == os.path.realpath(load)

        elif request.node._genid == 'fileobj':
            assert f.path == os.path.realpath(load.name)

        else:
            assert f.path is None

    @pytest.mark.parametrize("fload", ["/this/path/is/not/valid",
                                       pytest.mark.skipif(skipurls, "http://www.google.com/404", reason="No Internet")],
                             ids=["invalid-path", "invalid-url"])
    def test_load_fail(self, fload):
        with pytest.raises(e):
            FileLoader(fload)
{'fraction_non_alphanumeric': 0.1420469889278963, 'fraction_numerical': 0.0016203078584931137, 'mean_word_length': 2.432808155699722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4302883', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1181, 'n_words': 218}