2 # -*- coding: utf-8 -*-
5 from os
import path
, name
as os_name
6 from shutil
import copyfile
8 from manga_py
import fs
9 from manga_py
.base_classes
import Archive
11 root_path
= path
.dirname(path
.realpath(__file__
))
14 ['/files/img1.jpg', '/temp/img1.jpg'],
15 ['/files/img2.png', '/temp/img2.png'],
16 ['/files/img3.jpg', '/temp/img3.jpg'],
17 ['/files/img4.jpg', '/temp/img4.jpg'],
18 ['/files/img5.png', '/temp/img5.png'],
19 ['/files/img6.gif', '/temp/img6.gif'],
20 ['/files/img7.webp', '/temp/img7.webp'],
24 class TestArchive(unittest
.TestCase
):
26 def test_make_archive(self
):
28 arc_path
= root_path
+ '/temp/arc.zip'
31 for idx
, item
in enumerate(files_paths
):
32 fs
.unlink(root_path
+ item
[1])
33 copyfile(root_path
+ item
[0], root_path
+ item
[1])
34 orig_size
+= int(fs
.file_size(root_path
+ item
[1]))
35 arc
.add_file(root_path
+ item
[1])
37 copyfile(root_path
+ '/files/archive_test_image', root_path
+ '/temp/archive_test_image')
38 orig_size
+= int(fs
.file_size(root_path
+ '/temp/archive_test_image'))
39 arc
.add_file(root_path
+ '/temp/archive_test_image')
42 size
= fs
.file_size(arc_path
)
43 self
.assertTrue(size
and 1024 < int(size
) < orig_size
)
45 def test_rename(self
):
46 copyfile(root_path
+ '/files/archive_test_file', root_path
+ '/temp/archive_test_file')
47 fs
.rename(root_path
+ '/temp/archive_test_file', root_path
+ '/temp/archive_test_file1')
48 self
.assertTrue(fs
.is_file(root_path
+ '/temp/archive_test_file1'))
49 self
.assertFalse(fs
.is_file(root_path
+ '/temp/archive_test_file'))
53 self
.assertTrue(fs
.get_util_home_path().find('/home/') == 0)
54 self
.assertTrue(fs
.is_dir(fs
.get_util_home_path()))
56 def test_unlink1(self
):
57 _dir
= fs
.get_util_home_path()
58 fs
.make_dirs(_dir
+ '/dir')
59 self
.assertRaises(OSError, fs
.unlink
, _dir
)
61 def test_unlink2(self
):
62 _dir
= fs
.get_util_home_path()
63 fs
.make_dirs(_dir
+ '/dir')
65 self
.assertFalse(fs
.is_dir(_dir
))
67 def test_not_filesize(self
):
68 self
.assertIsNone(fs
.file_size(fs
.get_util_home_path() + '/file'))
70 def test_check_free_space1(self
):
71 self
.assertTrue(fs
.check_free_space(fs
.get_util_home_path(), min_size
=99))
73 def test_check_free_space2(self
):
74 self
.assertFalse(fs
.check_free_space(fs
.get_util_home_path(), 99, True))