1import unittest
2import optparse
3import os
4
5from giscanner.scannermain import get_source_root_dirs
6
7
8class TestScanner(unittest.TestCase):
9
10    def test_get_source_root_dirs_options(self):
11        options = optparse.Values({"sources_top_dirs": ["foo"]})
12        paths = get_source_root_dirs(options, ["nope"])
13        self.assertEqual(len(paths), 1)
14        self.assertTrue(os.path.isabs(paths[0]))
15        self.assertEqual(os.path.normcase(paths[0]),
16                         os.path.normcase(os.path.join(os.getcwd(), "foo")))
17
18    def test_get_source_root_dirs_guess(self):
19        options = optparse.Values({"sources_top_dirs": []})
20        cwd = os.getcwd()
21        paths = get_source_root_dirs(
22            options, [os.path.join(cwd, "foo"), os.path.join(cwd, "bar")])
23        self.assertEqual(len(paths), 1)
24        self.assertEqual(os.path.normcase(paths[0]), os.path.normcase(cwd))
25
26        paths = get_source_root_dirs(options, [])
27        self.assertEqual(paths, [])
28
29    @unittest.skipUnless(os.name == "nt", "Windows only")
30    def test_get_source_root_dirs_different_drives(self):
31        options = optparse.Values({"sources_top_dirs": []})
32        names = [
33            os.path.join("X:", os.sep, "foo"),
34            os.path.join("Y:", os.sep, "bar"),
35        ]
36        paths = get_source_root_dirs(options, names)
37        self.assertEqual(paths, list(map(os.path.dirname, names)))
38
39
40if __name__ == '__main__':
41    unittest.main()
42