2009-10-23 12:56:52 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-10-23
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2020-01-01 02:16:27 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-10-23 12:56:52 +00:00
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
2011-01-11 12:36:05 +00:00
|
|
|
from hscommon.path import Path
|
2011-01-05 10:11:21 +00:00
|
|
|
from hscommon.testutil import eq_
|
2009-12-30 10:37:57 +00:00
|
|
|
from core.tests.directories_test import create_fake_fs
|
2009-10-23 12:56:52 +00:00
|
|
|
|
|
|
|
from .. import fs
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-01-05 10:11:21 +00:00
|
|
|
def test_size_aggregates_subfiles(tmpdir):
|
|
|
|
p = create_fake_fs(Path(str(tmpdir)))
|
2011-04-12 11:22:29 +00:00
|
|
|
b = fs.Folder(p)
|
2011-01-05 10:11:21 +00:00
|
|
|
eq_(b.size, 12)
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-01-05 10:11:21 +00:00
|
|
|
def test_md5_aggregate_subfiles_sorted(tmpdir):
|
2020-01-01 02:16:27 +00:00
|
|
|
# dir.allfiles can return child in any order. Thus, bundle.md5 must aggregate
|
|
|
|
# all files' md5 it contains, but it must make sure that it does so in the
|
|
|
|
# same order everytime.
|
2011-01-05 10:11:21 +00:00
|
|
|
p = create_fake_fs(Path(str(tmpdir)))
|
2011-04-12 11:22:29 +00:00
|
|
|
b = fs.Folder(p)
|
2020-01-01 02:16:27 +00:00
|
|
|
md51 = fs.File(p["dir1"]["file1.test"]).md5
|
|
|
|
md52 = fs.File(p["dir2"]["file2.test"]).md5
|
|
|
|
md53 = fs.File(p["dir3"]["file3.test"]).md5
|
|
|
|
md54 = fs.File(p["file1.test"]).md5
|
|
|
|
md55 = fs.File(p["file2.test"]).md5
|
|
|
|
md56 = fs.File(p["file3.test"]).md5
|
2011-04-12 11:22:29 +00:00
|
|
|
# The expected md5 is the md5 of md5s for folders and the direct md5 for files
|
|
|
|
folder_md51 = hashlib.md5(md51).digest()
|
|
|
|
folder_md52 = hashlib.md5(md52).digest()
|
|
|
|
folder_md53 = hashlib.md5(md53).digest()
|
2020-01-01 02:16:27 +00:00
|
|
|
md5 = hashlib.md5(folder_md51 + folder_md52 + folder_md53 + md54 + md55 + md56)
|
2011-01-05 10:11:21 +00:00
|
|
|
eq_(b.md5, md5.digest())
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2011-01-05 10:11:21 +00:00
|
|
|
def test_has_file_attrs(tmpdir):
|
2020-01-01 02:16:27 +00:00
|
|
|
# a Folder must behave like a file, so it must have mtime attributes
|
2011-04-12 11:22:29 +00:00
|
|
|
b = fs.Folder(Path(str(tmpdir)))
|
2011-01-05 10:11:21 +00:00
|
|
|
assert b.mtime > 0
|
2020-01-01 02:16:27 +00:00
|
|
|
eq_(b.extension, "")
|