コード例 #1
0
 def setUp(self):
     file_fp, file_path = mkstemp()
     self.file_path = file_path
     stat = os.stat(self.file_path)
     self.file_attrs = {
         'pathname': os.path.basename(self.file_path),
         'size': stat.st_size,
         'ctime': int(time()),
         'mtime': stat.st_mtime,
         'mode': stat.st_mode,
     }
     self.file_object = FileEntry(**self.file_attrs)
     os.close(file_fp)
コード例 #2
0
ファイル: test_filetree.py プロジェクト: pmphxs/syncrypto
 def test_from_dict(self):
     stat = os.stat(self.file_path)
     d = {
         'pathname': os.path.basename(self.file_path),
         'fs_pathname': os.path.basename(self.file_path),
         'size': stat.st_size,
         'ctime': int(time()),
         'mtime': stat.st_mtime,
         'mode': stat.st_mode,
         'digest': None,
         'isdir': False,
         'salt': None
     }
     file_object = FileEntry(**d)
     self.assertEqual(d, file_object.to_dict())
コード例 #3
0
 def test_from_dict(self):
     stat = os.stat(self.file_path)
     d = {
         'pathname': os.path.basename(self.file_path),
         'fs_pathname': os.path.basename(self.file_path),
         'size': stat.st_size,
         'ctime': int(time()),
         'mtime': stat.st_mtime,
         'mode': stat.st_mode,
         'digest': None,
         'isdir': False,
         'salt': None
     }
     file_object = FileEntry(**d)
     self.assertEqual(d, file_object.to_dict())
コード例 #4
0
ファイル: test_crypto.py プロジェクト: wangjun/syncrypto
 def setUp(self):
     file_fp, file_path = mkstemp()
     self.password = "******"
     self.crypto = Crypto(self.password)
     self.file_path = file_path
     self.file_entry = FileEntry.from_file(file_path, os.path.basename(file_path))
     os.close(file_fp)
コード例 #5
0
ファイル: test_crypto.py プロジェクト: cengjing/syncrypto
 def setUp(self):
     file_fp, file_path = mkstemp()
     self.password = '******'
     self.crypto = Crypto(self.password)
     self.file_path = file_path
     self.file_entry = FileEntry.from_file(file_path,
                                           os.path.basename(file_path))
     os.close(file_fp)
コード例 #6
0
ファイル: test_filetree.py プロジェクト: malongge/syncrypto
 def setUp(self):
     file_fp, file_path = mkstemp()
     self.file_path = file_path
     stat = os.stat(self.file_path)
     self.file_attrs = {
         'pathname': os.path.basename(self.file_path),
         'size': stat.st_size,
         'ctime': int(time()),
         'mtime': stat.st_mtime,
         'mode': stat.st_mode,
     }
     self.file_object = FileEntry(**self.file_attrs)
     os.close(file_fp)
コード例 #7
0
 def test_from_file(self):
     stat = os.stat(self.file_path)
     d = {
         'pathname': os.path.basename(self.file_path),
         'fs_pathname': os.path.basename(self.file_path),
         'size': stat.st_size,
         'ctime': stat.st_ctime,
         'mtime': stat.st_mtime,
         'mode': stat.st_mode,
         'digest': file_hexlify_digest(self.file_path),
         'isdir': False,
         'salt': None
     }
     if is_windows:
         d['mode'] = None
     file_object = FileEntry.from_file(self.file_path, d['pathname'])
     self.assertEqual(d, file_object.to_dict())
コード例 #8
0
ファイル: test_filetree.py プロジェクト: malongge/syncrypto
 def test_from_file(self):
     stat = os.stat(self.file_path)
     d = {
         'pathname': os.path.basename(self.file_path),
         'fs_pathname': os.path.basename(self.file_path),
         'size': stat.st_size,
         'ctime': stat.st_ctime,
         'mtime': stat.st_mtime,
         'mode': stat.st_mode,
         'digest': file_hexlify_digest(self.file_path),
         'isdir': False,
         'salt': None
     }
     if is_windows:
         d['mode'] = None
     file_object = FileEntry.from_file(self.file_path, d['pathname'])
     self.assertEqual(d, file_object.to_dict())
コード例 #9
0
class FileEntryTestCase(unittest.TestCase):
    def setUp(self):
        file_fp, file_path = mkstemp()
        self.file_path = file_path
        stat = os.stat(self.file_path)
        self.file_attrs = {
            'pathname': os.path.basename(self.file_path),
            'size': stat.st_size,
            'ctime': int(time()),
            'mtime': stat.st_mtime,
            'mode': stat.st_mode,
        }
        self.file_object = FileEntry(**self.file_attrs)
        os.close(file_fp)

    def tearDown(self):
        os.remove(self.file_path)

    def test_property(self):
        stat = os.stat(self.file_path)
        self.assertEqual(self.file_object.isdir, False)
        self.assertEqual(self.file_object.digest, None)
        self.assertEqual(self.file_object.size, stat.st_size)
        self.assertEqual(self.file_object.ctime, int(stat.st_ctime))
        self.assertEqual(self.file_object.mtime, stat.st_mtime)
        self.assertEqual(self.file_object.mode, stat.st_mode)
        self.assertEqual(self.file_object.pathname,
                         os.path.basename(self.file_path))

    def test_to_dict(self):
        d = self.file_object.to_dict()
        for k in self.file_attrs:
            self.assertEqual(d[k], self.file_attrs[k])

    def test_from_file(self):
        stat = os.stat(self.file_path)
        d = {
            'pathname': os.path.basename(self.file_path),
            'fs_pathname': os.path.basename(self.file_path),
            'size': stat.st_size,
            'ctime': stat.st_ctime,
            'mtime': stat.st_mtime,
            'mode': stat.st_mode,
            'digest': file_hexlify_digest(self.file_path),
            'isdir': False,
            'salt': None
        }
        if is_windows:
            d['mode'] = None
        file_object = FileEntry.from_file(self.file_path, d['pathname'])
        self.assertEqual(d, file_object.to_dict())

    def test_from_dict(self):
        stat = os.stat(self.file_path)
        d = {
            'pathname': os.path.basename(self.file_path),
            'fs_pathname': os.path.basename(self.file_path),
            'size': stat.st_size,
            'ctime': int(time()),
            'mtime': stat.st_mtime,
            'mode': stat.st_mode,
            'digest': file_digest(self.file_path),
            'isdir': False,
            'salt': None
        }
        file_object = FileEntry(**d)
        d['digest'] = hexlify(d['digest'])
        self.assertEqual(d, file_object.to_dict())
コード例 #10
0
ファイル: test_rule.py プロジェクト: malongge/syncrypto
 def setUp(self):
     file_fp, file_path = mkstemp()
     self.file_path = file_path
     self.file_entry = FileEntry.from_file(self.file_path, os.path.basename(
         self.file_path))
     os.close(file_fp)
コード例 #11
0
ファイル: test_filetree.py プロジェクト: malongge/syncrypto
class FileEntryTestCase(unittest.TestCase):

    def setUp(self):
        file_fp, file_path = mkstemp()
        self.file_path = file_path
        stat = os.stat(self.file_path)
        self.file_attrs = {
            'pathname': os.path.basename(self.file_path),
            'size': stat.st_size,
            'ctime': int(time()),
            'mtime': stat.st_mtime,
            'mode': stat.st_mode,
        }
        self.file_object = FileEntry(**self.file_attrs)
        os.close(file_fp)

    def tearDown(self):
        os.remove(self.file_path)

    def test_property(self):
        stat = os.stat(self.file_path)
        self.assertEqual(self.file_object.isdir, False)
        self.assertEqual(self.file_object.digest, None)
        self.assertEqual(self.file_object.size, stat.st_size)
        self.assertEqual(self.file_object.ctime, int(stat.st_ctime))
        self.assertEqual(self.file_object.mtime, stat.st_mtime)
        self.assertEqual(self.file_object.mode, stat.st_mode)
        self.assertEqual(self.file_object.pathname,
                         os.path.basename(self.file_path))

    def test_to_dict(self):
        d = self.file_object.to_dict()
        for k in self.file_attrs:
            self.assertEqual(d[k], self.file_attrs[k])

    def test_from_file(self):
        stat = os.stat(self.file_path)
        d = {
            'pathname': os.path.basename(self.file_path),
            'fs_pathname': os.path.basename(self.file_path),
            'size': stat.st_size,
            'ctime': stat.st_ctime,
            'mtime': stat.st_mtime,
            'mode': stat.st_mode,
            'digest': file_hexlify_digest(self.file_path),
            'isdir': False,
            'salt': None
        }
        if is_windows:
            d['mode'] = None
        file_object = FileEntry.from_file(self.file_path, d['pathname'])
        self.assertEqual(d, file_object.to_dict())

    def test_from_dict(self):
        stat = os.stat(self.file_path)
        d = {
            'pathname': os.path.basename(self.file_path),
            'fs_pathname': os.path.basename(self.file_path),
            'size': stat.st_size,
            'ctime': int(time()),
            'mtime': stat.st_mtime,
            'mode': stat.st_mode,
            'digest': file_digest(self.file_path),
            'isdir': False,
            'salt': None
        }
        file_object = FileEntry(**d)
        d['digest'] = hexlify(d['digest'])
        self.assertEqual(d, file_object.to_dict())
コード例 #12
0
ファイル: test_rule.py プロジェクト: sharpglasses/syncrypto
 def setUp(self):
     file_fp, file_path = mkstemp()
     self.file_path = file_path
     self.file_entry = FileEntry.from_file(self.file_path,
                                           os.path.basename(self.file_path))
     os.close(file_fp)