# Copyright (c) 2019 Red Hat, Inc.
#
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
from __future__ import absolute_import

import os
import typing

import testtools

from tobiko import run


class FindTestFilesTest(testtools.TestCase):

    def test_find_test_files(self,
                             test_path: typing.List[str] = None):
        if test_path is None:
            test_path = [__file__]
        test_files = run.find_test_files(test_path=test_path)
        self.assertIn(__file__, test_files)
        test_path = [os.path.realpath(path)
                     for path in test_path]
        for test_file in test_files:
            for path in test_path:
                if test_file.startswith(path):
                    break
            else:
                self.fail(f"File '{test_file}' not in any path ({test_path})")

    def test_find_test_files_with_test_dir(self):
        return self.test_find_test_files(
            test_path=[os.path.dirname(__file__)])
