コード例 #1
0
    def test_assert_exists(self):
        path_type = types.PathType(assert_exists=True)
        path_type(__file__)

        with self.assertRaises(ArgumentTypeError):
            path_type('/nonsensisal/path/')

        with self.assertRaises(ArgumentTypeError):
            path_type('~/not-a-real/path to a file')
コード例 #2
0
    def test_assert_executable(self):
        if platform.system() == 'Windows':
            self.skipTest("All files are considered executable in Windows")

        path_type = types.PathType(assert_executable=True)

        bash_path = '/bin/bash'
        if os.path.isfile(bash_path) and os.access(bash_path, os.X_OK):
            path_type(bash_path)

        with self.assertRaises(ArgumentTypeError):
            path_type(__file__)
コード例 #3
0
    def test_expands_path(self):
        path_type = types.PathType()

        path = path_type('/some/random/path/../')
        self.assertEqual(self._platform_path('/some/random'), path)

        path = path_type('~/path/to/some/file.txt')
        self.assertEqual(
            self._platform_path(self.home_dir + '/path/to/some/file.txt'),
            path)

        path = path_type('~/path/to/some/../file.txt')
        self.assertEqual(
            self._platform_path(self.home_dir + '/path/to/file.txt'), path)