<commit_before>if __name__ == "__main__" and __package__ is None:
    from os import sys, path
    sys.path.insert(0, path.dirname(path.dirname(__file__)))

from toml import TomlDecodeError  # noqa: E402
import toml  # noqa: E402
import warnings  # noqa: E402


class TestDict(dict):
    pass


try:
    FNFError = FileNotFoundError
except NameError:
    FNFError = IOError


TEST_STR = """
[a]
b = 1
c = 2
"""

INVALID_TOML = """
strings-and-ints = ["hi", 42]
"""

TEST_DICT = {"a": {"b": 1, "c": 2}}

o = toml.loads(TEST_STR)
assert(o == toml.loads(toml.dumps(o)))
assert(isinstance(toml.loads(TEST_STR, _dict=TestDict), TestDict))

try:
    toml.loads(2)
    # Expected TypeError
    assert(False)
except TypeError:
    pass

try:
    toml.loads(INVALID_TOML)
    # Expected TomlDecodeError
    assert(False)
except TomlDecodeError:
    pass

try:<commit_msg>Add TomlDecoder to API tests<commit_after>if __name__ == "__main__" and __package__ is None:
    from os import sys, path
    sys.path.insert(0, path.dirname(path.dirname(__file__)))

from toml import TomlDecoder, TomlDecodeError  # noqa: E402
import toml  # noqa: E402
import warnings  # noqa: E402


class TestDict(dict):
    pass


try:
    FNFError = FileNotFoundError
except NameError:
    FNFError = IOError


TEST_STR = """
[a]
b = 1
c = 2
"""

INVALID_TOML = """
strings-and-ints = ["hi", 42]
"""

TEST_DICT = {"a": {"b": 1, "c": 2}}

o = toml.loads(TEST_STR)
test_dict_decoder = TomlDecoder(TestDict)
assert(o == toml.loads(toml.dumps(o)))
assert(isinstance(toml.loads(TEST_STR, decoder=test_dict_decoder), TestDict))

try:
    toml.loads(2)
    # Expected TypeError
    assert(False)
except TypeError:
    pass

try:
    toml.loads(INVALID_TOML)
    # Expected TomlDecodeError
    assert(False)
except TomlDecodeError:
    pass

try:
{'fraction_non_alphanumeric': 0.1296398891966759, 'fraction_numerical': 0.018836565096952907, 'mean_word_length': 3.975206611570248, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1954057', 'n_tokens_mistral': 712, 'n_tokens_neox': 692, 'n_words': 162}