1 # Copyright (C) 2018 Facebook
3 # This file is part of libbtrfsutil.
5 # libbtrfsutil is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # libbtrfsutil is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with libbtrfsutil. If not, see <http://www.gnu.org/licenses/>.
22 from pathlib import PurePath
26 from tests import BtrfsTestCase
29 class TestSubvolume(BtrfsTestCase):
30 def test_is_subvolume(self):
31 dir = os.path.join(self.mountpoint, 'foo')
34 for arg in self.path_or_fd(self.mountpoint):
35 with self.subTest(type=type(arg)):
36 self.assertTrue(btrfsutil.is_subvolume(arg))
37 for arg in self.path_or_fd(dir):
38 with self.subTest(type=type(arg)):
39 self.assertFalse(btrfsutil.is_subvolume(arg))
41 with self.assertRaises(btrfsutil.BtrfsUtilError) as e:
42 btrfsutil.is_subvolume(os.path.join(self.mountpoint, 'bar'))
43 # This is a bit of an implementation detail, but really this is testing
44 # that the exception is initialized correctly.
45 self.assertEqual(e.exception.btrfsutilerror, btrfsutil.ERROR_STATFS_FAILED)
46 self.assertEqual(e.exception.errno, errno.ENOENT)
48 def test_subvolume_id(self):
49 dir = os.path.join(self.mountpoint, 'foo')
52 for arg in self.path_or_fd(self.mountpoint):
53 with self.subTest(type=type(arg)):
54 self.assertEqual(btrfsutil.subvolume_id(arg), 5)
55 for arg in self.path_or_fd(dir):
56 with self.subTest(type=type(arg)):
57 self.assertEqual(btrfsutil.subvolume_id(arg), 5)