#  Copyright 2020 Modelling, Simulation and Design Lab (MSDL) at
#  McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
#
#  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.

"""Test that the file handling used in dynamic linking is accurate.

See Also:
    :mod:`pypdevsbbl.extra.fileutils`
"""

import unittest
import os

from pypdevsbbl.extra import fileutils


class TestFileutils(unittest.TestCase):
    def test_src(self):
        """Tests the ``src`` folder location."""
        assert fileutils.src() == os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
        assert fileutils.src("test", "extra", "test_fileutils.py") == __file__
        assert fileutils.src("pypdevsbbl") == fileutils.pypdevsbbl()
        assert fileutils.src("dependencies") == fileutils.dependencies()
        assert fileutils.src("test") == fileutils.test()

    def test_pypdevsbbl(self):
        """Tests the ``pypdevsbbl`` folder location."""
        assert fileutils.pypdevsbbl() == os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "pypdevsbbl"))
        assert fileutils.pypdevsbbl("..", "test", "extra", "test_fileutils.py") == __file__
        assert fileutils.pypdevsbbl("..") == fileutils.src()

    def test_dependencies(self):
        """Tests the ``dependencies`` folder location."""
        assert fileutils.dependencies() == os.path.abspath(
            os.path.join(os.path.dirname(__file__), "..", "..", "dependencies"))
        assert fileutils.dependencies("..", "test", "extra", "test_fileutils.py") == __file__
        assert fileutils.dependencies("..") == fileutils.src()

    def test_test(self):
        """Tests the ``test`` folder location."""
        assert fileutils.test() == os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
        assert fileutils.test("extra", "test_fileutils.py") == __file__
        assert fileutils.test("..") == fileutils.src()

if __name__ == '__main__':
    unittest.main()
