예제 #1
0
    def test_other_copy(self):
        for propname in metadata.FileMetaData.propnames:
            for boolval in [True, False]:
                propdic = dict()
                propdic[propname] = boolval

                self.assertEqual(
                    getattr(
                        metadata.FileMetaData(other=metadata.FileMetaData(
                            props=propdic)), propname), boolval)
예제 #2
0
    def test_write_protection(self):
        md = metadata.FileMetaData()

        def assign_test():
            md.user_write = False

        self.assertRaises(AssertionError, assign_test)
예제 #3
0
    def test_dict_iface(self):
        for propname in metadata.FileMetaData.propnames:
            for boolval in [True, False]:
                propdic = dict()
                propdic[propname] = boolval

                self.assertEqual(
                    metadata.FileMetaData(props=propdic)[propname], boolval)
예제 #4
0
    def test_init_assignment(self):
        for propname in metadata.FileMetaData.propnames:
            for boolval in [True, False]:
                propdic = dict()
                propdic[propname] = boolval

                self.assertEqual(
                    getattr(metadata.FileMetaData(props=propdic), propname),
                    boolval)
예제 #5
0
    def test_to_string_from_string(self):
        d = dict(is_directory=True,
                 is_regular=False,
                 is_symlink=False,
                 is_block_device=False,
                 is_character_device=False,
                 is_fifo=False,
                 user_read=True,
                 user_write=True,
                 user_execute=True,
                 group_read=True,
                 group_write=False,
                 group_execute=True,
                 other_read=True,
                 other_write=False,
                 other_execute=True,
                 is_setuid=False,
                 is_setgid=False,
                 is_sticky=False,
                 uid=5,
                 gid=6,
                 size=7,
                 atime=8,
                 mtime=9,
                 ctime=10)
        md = metadata.FileMetaData(d)

        self.assertEqual(md.to_string(), 'drwxr-xr-x 5 6 7 8 9 10')
        self.assertEqual(
            metadata.FileMetaData.from_string(md.to_string()).to_string(),
            'drwxr-xr-x 5 6 7 8 9 10')

        def from_s(s):
            return metadata.FileMetaData.from_string(s)

        self.assertRaises(AssertionError, from_s,
                          'drwxr-xr-x 5 6 7 8 9 10 extra')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x 5 6 7 8 9 notint')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x 5 6 7 8 notint 10')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x 5 6 7 notint 9 10')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x 5 6 7 notint 9 10')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x 5 6 notint 8 9 10')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x 5 notint 7 8 9 10')
        self.assertRaises(ValueError, from_s, 'drwxr-xr-x notint 6 7 8 9 10')

        self.assertRaises(AssertionError, from_s, 'drwxr-xr-x! 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drwxr-xr-! 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drwxr-xr!x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drwxr-x!-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drwxr-!r-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drwxr!xr-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drwx!-xr-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'drw!r-xr-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'dr!xr-xr-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, 'd!wxr-xr-x 5 6 7 8 9 10')
        self.assertRaises(AssertionError, from_s, '!rwxr-xr-x 5 6 7 8 9 10')