• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import os
4import unittest
5
6from vndk_definition_tool import scandir
7
8
9class ScanDirTest(unittest.TestCase):
10    def test_scandir(self):
11        testdata_dir = os.path.join(
12            os.path.dirname(__file__), 'testdata', 'test_scandir')
13
14        num_entries = 0
15        for ent in scandir(testdata_dir):
16            num_entries += 1
17
18            self.assertEqual(ent.path, os.path.join(testdata_dir, ent.name))
19
20            if ent.name == 'test_file':
21                self.assertTrue(ent.is_file())
22                self.assertFalse(ent.is_dir())
23                self.assertFalse(ent.is_symlink())
24            elif ent.name == 'test_dir':
25                self.assertFalse(ent.is_file())
26                self.assertTrue(ent.is_dir())
27                self.assertFalse(ent.is_symlink())
28            elif ent.name == 'link_test_file':
29                self.assertTrue(ent.is_file())
30                self.assertFalse(ent.is_file(follow_symlinks=False))
31                self.assertFalse(ent.is_dir())
32                self.assertFalse(ent.is_dir(follow_symlinks=False))
33                self.assertTrue(ent.is_symlink())
34            elif ent.name == 'link_test_dir':
35                self.assertFalse(ent.is_file())
36                self.assertFalse(ent.is_file(follow_symlinks=False))
37                self.assertTrue(ent.is_dir())
38                self.assertFalse(ent.is_dir(follow_symlinks=False))
39                self.assertTrue(ent.is_symlink())
40            elif ent.name == 'link_does_not_exist':
41                self.assertFalse(ent.is_file())
42                self.assertFalse(ent.is_file(follow_symlinks=False))
43                self.assertFalse(ent.is_dir())
44                self.assertFalse(ent.is_dir(follow_symlinks=False))
45                self.assertTrue(ent.is_symlink())
46            else:
47                self.fail('unexpected filename: ' + ent.name)
48
49        self.assertEqual(num_entries, 5)
50