Debian Codegraph @

scripts/python/TerraSync/tests/test_dirindex.py

raw symbols SCIP
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # test_dirindex.py --- Test module for terrasync.dirindex
5 # Copyright (C) 2020 Florent Rougon
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 # In order to exercise all tests, run the following command from the parent
22 # directory (you may omit the 'discover' argument):
23 #
24 # python3 -m unittest discover
25
26 """Test module for terrasync.dirindex"""
27
28 import os
29 import unittest
30 from terrasync.dirindex import DirIndex
31 from terrasync.exceptions import InvalidDirIndexFile
32 from terrasync.virtual_path import VirtualPath
33
34
35 baseDir = os.path.dirname(__file__)
36
37 def testData(*args):
38 return os.path.join(baseDir, "data", "dirindex", *args)
39
40
41 directories_in_sample_dirindex_1 = [
42 {'name': 'Airports', 'hash': '8a93b5d8a2b04d2fb8de4ef58ad02f9e8819d314'},
43 {'name': 'Models', 'hash': 'bee221c9d2621dc9b69cd9e0ad7dd0605f6ea928'},
44 {'name': 'Objects', 'hash': '10ae32c986470fa55b56b8eefbc6ed565cce0642'},
45 {'name': 'Terrain', 'hash': 'e934024dc0f959f9a433e47c646d256630052c2e'},
46 {'name': 'Buildings', 'hash': '19060725efc2a301fa6844991e2922d42d8de5e2'},
47 {'name': 'Pylons', 'hash': '378b3dd58ce3058f2992b70aa5ecf8947a4d7f9e'},
48 {'name': 'Roads', 'hash': '89f8f10406041948368c76c0a2e794d45ac536b7'}]
49
50 files_in_sample_dirindex_1 = [
51 {'name': 'some file',
52 'hash': '4cbf3d1746a1249bff7809e4b079dd80cfce594c',
53 'size': 123},
54 {'name': 'other file',
55 'hash': '62726252f7183eef31001c1c565e149f3c4527b9',
56 'size': 4567},
57 {'name': 'third file',
58 'hash': '303adcc1747d8dc438096307189881e987e9bb61',
59 'size': 89012}]
60
61 tarballs_in_sample_dirindex_1 = [
62 {'name': 'Airports_archive.tgz',
63 'hash': 'b63a067d82824f158d6bde66f9e76654274277fe',
64 'size': 1234567}]
65
66
67 class TestDirIndex(unittest.TestCase):
68 """Unit tests for the DirIndex class."""
69
70 def test_constructor(self):
71 d = DirIndex(testData("good", "sample_dirindex_1"))
72 self.assertEqual(d.version, 1)
73 self.assertEqual(d.path, VirtualPath("some/path"))
74 self.assertEqual(d.directories, directories_in_sample_dirindex_1)
75 self.assertEqual(d.files, files_in_sample_dirindex_1)
76 self.assertEqual(d.tarballs, tarballs_in_sample_dirindex_1)
77
78 stems = ("path_starts_with_slash",
79 "path_contains_a_backslash",
80 "dotdot_in_path",
81 "slash_in_directory_name",
82 "slash_in_file_name",
83 "slash_in_tarball_name",
84 "backslash_in_directory_name",
85 "backslash_in_file_name",
86 "backslash_in_tarball_name",
87 "directory_name_is_double_colon",
88 "file_name_is_double_colon",
89 "tarball_name_is_double_colon",)
90 for stem in stems:
91 with self.assertRaises(InvalidDirIndexFile):
92 DirIndex(testData("bad", "bad_dirindex_" + stem))
93
94 with self.assertRaises(UnicodeDecodeError):
95 d = DirIndex(testData("bad", "bad_dirindex_encoding"))