diff options
Diffstat (limited to 'src/fs/test_gnunet_fs_psd.py.in')
-rwxr-xr-x | src/fs/test_gnunet_fs_psd.py.in | 108 |
1 files changed, 60 insertions, 48 deletions
diff --git a/src/fs/test_gnunet_fs_psd.py.in b/src/fs/test_gnunet_fs_psd.py.in index 601797c82..906282200 100755 --- a/src/fs/test_gnunet_fs_psd.py.in +++ b/src/fs/test_gnunet_fs_psd.py.in | |||
@@ -2,20 +2,18 @@ | |||
2 | # This file is part of GNUnet. | 2 | # This file is part of GNUnet. |
3 | # (C) 2010, 2018 Christian Grothoff (and other contributing authors) | 3 | # (C) 2010, 2018 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 5 | # GNUnet is free software: you can redistribute it and/or modify it |
6 | # it under the terms of the GNU General Public License as published | 6 | # under the terms of the GNU Affero General Public License as published |
7 | # by the Free Software Foundation; either version 2, or (at your | 7 | # by the Free Software Foundation, either version 3 of the License, |
8 | # option) any later version. | 8 | # or (at your option) any later version. |
9 | # | 9 | # |
10 | # GNUnet is distributed in the hope that it will be useful, but | 10 | # GNUnet is distributed in the hope that it will be useful, but |
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | # General Public License for more details. | 13 | # Affero General Public License for more details. |
14 | # | 14 | # |
15 | # You should have received a copy of the GNU General Public License | 15 | # You should have received a copy of the GNU Affero General Public License |
16 | # along with GNUnet; see the file COPYING. If not, write to the | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | # Boston, MA 02110-1301, USA. | ||
19 | # | 17 | # |
20 | # Testcase for file-sharing command-line tools (publish, search, download) | 18 | # Testcase for file-sharing command-line tools (publish, search, download) |
21 | import sys | 19 | import sys |
@@ -24,64 +22,78 @@ import subprocess | |||
24 | import re | 22 | import re |
25 | import shutil | 23 | import shutil |
26 | try: | 24 | try: |
25 | # Python 2.7 | ||
27 | reload | 26 | reload |
28 | except NameError: | 27 | except NameError: |
29 | # python3.4: | 28 | try: |
30 | from importlib import reload | 29 | # Python 3.4+: |
30 | from importlib import reload | ||
31 | except ImportError: | ||
32 | # Python 3.0 - 3.3 | ||
33 | from imp import reload | ||
31 | 34 | ||
32 | # Force encoding to utf-8, as this test otherwise fails | ||
33 | # on some systems (see #5094). | ||
34 | reload(sys) | 35 | reload(sys) |
35 | sys.setdefaultencoding('utf8') | 36 | |
37 | # Force encoding to utf-8, as this test otherwise fails | ||
38 | # on some systems (see #5094). In Python 3+ there is no attribute | ||
39 | # sys.setdefaultencoding anymore. | ||
40 | if (3 < sys.version_info[0]): | ||
41 | sys.setdefaultencoding('utf8') | ||
36 | 42 | ||
37 | srcdir = "../.." | 43 | srcdir = "../.." |
38 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 44 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
39 | if gnunet_pyexpect_dir not in sys.path: | 45 | if gnunet_pyexpect_dir not in sys.path: |
40 | sys.path.append (gnunet_pyexpect_dir) | 46 | sys.path.append(gnunet_pyexpect_dir) |
41 | 47 | ||
42 | from gnunet_pyexpect import pexpect | 48 | from gnunet_pyexpect import pexpect |
43 | 49 | ||
44 | if os.name == 'posix': | 50 | if os.name == 'posix': |
45 | download = './gnunet-download' | 51 | download = './gnunet-download' |
46 | gnunetarm = 'gnunet-arm' | 52 | gnunetarm = 'gnunet-arm' |
47 | publish = './gnunet-publish' | 53 | publish = './gnunet-publish' |
48 | unindex = './gnunet-unindex' | 54 | unindex = './gnunet-unindex' |
49 | search = './gnunet-search' | 55 | search = './gnunet-search' |
50 | elif os.name == 'nt': | 56 | elif os.name == 'nt': |
51 | download = './gnunet-download.exe' | 57 | download = './gnunet-download.exe' |
52 | gnunetarm = 'gnunet-arm.exe' | 58 | gnunetarm = 'gnunet-arm.exe' |
53 | publish = './gnunet-publish.exe' | 59 | publish = './gnunet-publish.exe' |
54 | unindex = './gnunet-unindex.exe' | 60 | unindex = './gnunet-unindex.exe' |
55 | search = './gnunet-search.exe' | 61 | search = './gnunet-search.exe' |
56 | 62 | ||
63 | if "GNUNET_PREFIX" in os.environ: | ||
64 | pass | ||
65 | else: | ||
66 | print("You need to export GNUNET_PREFIX") | ||
67 | sys.exit(1) | ||
68 | |||
57 | if os.name == "nt": | 69 | if os.name == "nt": |
58 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-psd"), True) | 70 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) |
59 | else: | 71 | else: |
60 | shutil.rmtree ("/tmp/gnunet-test-fs-py-psd", True) | 72 | shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) |
61 | 73 | ||
62 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_psd_data.conf']) | 74 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_psd_data.conf']) |
63 | arm.communicate () | 75 | arm.communicate() |
64 | 76 | ||
65 | # first, basic publish-search-download run | 77 | # first, basic publish-search-download run |
66 | try: | 78 | try: |
67 | pub = pexpect () | 79 | pub = pexpect() |
68 | pub.spawn (None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 80 | pub.spawn(None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
69 | pub.expect ("stdout", re.compile (r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")) | 81 | pub.expect("stdout", re.compile(r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")) |
70 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) | 82 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) |
71 | 83 | ||
72 | s = pexpect () | 84 | s = pexpect() |
73 | s.spawn (None, [search, '-V', '-t', '1000 ms', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'tst'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 85 | s.spawn(None, [search, '-V', '-t', '1000 ms', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'tst'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
74 | s.expect ("stdout", re.compile (r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n')) | 86 | s.expect("stdout", re.compile(r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n')) |
75 | 87 | ||
76 | down = pexpect () | 88 | down = pexpect() |
77 | down.spawn (None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 89 | down.spawn(None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
78 | down.expect ("stdout", re.compile (r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) | 90 | down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) |
79 | os.remove ("test_gnunet_fs_rec_data.tar.gz") | 91 | os.remove("test_gnunet_fs_rec_data.tar.gz") |
80 | 92 | ||
81 | finally: | 93 | finally: |
82 | arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf']) | 94 | arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf']) |
83 | arm.communicate () | 95 | arm.communicate() |
84 | if os.name == "nt": | 96 | if os.name == "nt": |
85 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-psd"), True) | 97 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) |
86 | else: | 98 | else: |
87 | shutil.rmtree ("/tmp/gnunet-test-fs-py-psd", True) | 99 | shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) |