<commit_before>#
# Copyright (C) 2012 <NAME> <ssato @ redhat.com>
# License: MIT
#
# pylint: disable=missing-docstring
import unittest
import anyconfig.utils as TT


class Test(unittest.TestCase):

    def test_00_get_file_extension(self):
        self.assertEqual(TT.get_file_extension("/a/b/c"), '')
        self.assertEqual(TT.get_file_extension("/a/b.txt"), "txt")
        self.assertEqual(TT.get_file_extension("/a/b/c.tar.xz"), "xz")

# vim:sw=4:ts=4:et:
<commit_msg>change: add .utils.expand_paths test cases<commit_after>#
# Copyright (C) 2012 <NAME> <ssato @ redhat.com>
# Copyright (C) 2019 - 2020 <NAME> <<EMAIL>>
# SPDX-License-Identifier: MIT
#
# pylint: disable=missing-docstring,invalid-name
r"""test cases for anyconfig.utils.
"""
import pathlib
import unittest

import anyconfig.ioinfo
import anyconfig.utils as TT

import tests.common


class Test(unittest.TestCase):

    def test_00_get_file_extension(self):
        self.assertEqual(TT.get_file_extension("/a/b/c"), '')
        self.assertEqual(TT.get_file_extension("/a/b.txt"), "txt")
        self.assertEqual(TT.get_file_extension("/a/b/c.tar.xz"), "xz")


class TestCaseWithWorkdir(tests.common.TestCaseWithWorkdir):

    def test_10_expand_paths(self):
        fun = TT.expand_paths

        tdir = self.workdir / "a" / "b" / "c"
        tdir.mkdir(parents=True)

        pathlib.Path(tdir / 'd.txt').touch()
        pathlib.Path(tdir / 'e.txt').touch()
        pathlib.Path(tdir / 'f.json').write_text("{'a': 1}\n")

        # single path:
        path = tdir / 'd.txt'
        self.assertEqual(fun(str(path)), [path])
        self.assertEqual(fun(path), [path])
        with path.open() as fobj:
            self.assertEqual(fun(fobj), [fobj])
        self.assertEqual(fun(anyconfig.ioinfo.make(path)), [path])

        # single path contains a glob pattern:
        self.assertEqual(fun(tdir / '*.txt'),
                         [tdir / 'd.txt', tdir / 'e.txt'])
        self.assertEqual(fun(tdir.parent / '**' / '*.txt'),
                         [tdir / 'd.txt', tdir / 'e.txt'])
        self.assertEqual(fun(tdir.parent / '**' / '*.*'),
                         [tdir / 'd.txt', tdir / 'e.txt', tdir / 'f.json'])

        # multiple paths:
        self.assertEqual(fun([tdir / 'e.txt', tdir / 'd.txt']),
                         [tdir / 'd.txt', tdir / 'e.txt'])

# vim:sw=4:ts=4:et:

{'fraction_non_alphanumeric': 0.17455621301775148, 'fraction_numerical': 0.011411665257819104, 'mean_word_length': 2.6584234930448223, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '712572', 'n_tokens_mistral': 861, 'n_tokens_neox': 814, 'n_words': 145}