appier 1.31.4__py2.py3-none-any.whl → 1.32.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appier/__init__.py +333 -52
- appier/amqp.py +29 -30
- appier/api.py +214 -212
- appier/asgi.py +54 -55
- appier/async_neo.py +46 -35
- appier/async_old.py +55 -42
- appier/asynchronous.py +7 -13
- appier/base.py +1762 -1429
- appier/bus.py +51 -52
- appier/cache.py +99 -84
- appier/common.py +9 -11
- appier/component.py +17 -19
- appier/compress.py +25 -28
- appier/config.py +96 -73
- appier/controller.py +9 -15
- appier/crypt.py +25 -21
- appier/data.py +73 -57
- appier/defines.py +191 -226
- appier/exceptions.py +103 -63
- appier/execution.py +94 -88
- appier/export.py +90 -88
- appier/extra.py +6 -13
- appier/extra_neo.py +8 -11
- appier/extra_old.py +18 -16
- appier/geo.py +57 -47
- appier/git.py +101 -90
- appier/graph.py +23 -24
- appier/http.py +520 -398
- appier/legacy.py +373 -180
- appier/log.py +90 -97
- appier/meta.py +42 -42
- appier/mock.py +32 -34
- appier/model.py +793 -681
- appier/model_a.py +208 -183
- appier/mongo.py +183 -107
- appier/observer.py +39 -31
- appier/part.py +23 -24
- appier/preferences.py +44 -47
- appier/queuing.py +78 -96
- appier/redisdb.py +40 -35
- appier/request.py +227 -175
- appier/scheduler.py +13 -18
- appier/serialize.py +37 -31
- appier/session.py +161 -147
- appier/settings.py +2 -11
- appier/smtp.py +53 -49
- appier/storage.py +39 -33
- appier/structures.py +50 -45
- appier/test/__init__.py +2 -11
- appier/test/base.py +111 -108
- appier/test/cache.py +28 -35
- appier/test/config.py +10 -19
- appier/test/crypt.py +3 -12
- appier/test/data.py +3 -12
- appier/test/exceptions.py +8 -17
- appier/test/export.py +16 -33
- appier/test/graph.py +27 -60
- appier/test/http.py +42 -54
- appier/test/legacy.py +20 -30
- appier/test/log.py +14 -35
- appier/test/mock.py +27 -123
- appier/test/model.py +79 -91
- appier/test/part.py +5 -14
- appier/test/preferences.py +5 -13
- appier/test/queuing.py +29 -37
- appier/test/request.py +61 -73
- appier/test/serialize.py +12 -23
- appier/test/session.py +10 -19
- appier/test/smtp.py +8 -14
- appier/test/structures.py +20 -24
- appier/test/typesf.py +14 -28
- appier/test/util.py +480 -438
- appier/typesf.py +251 -171
- appier/util.py +578 -407
- appier/validation.py +280 -143
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/METADATA +6 -1
- appier-1.32.0.dist-info/RECORD +86 -0
- appier-1.31.4.dist-info/RECORD +0 -86
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/LICENSE +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/WHEEL +0 -0
- {appier-1.31.4.dist-info → appier-1.32.0.dist-info}/top_level.txt +0 -0
appier/test/config.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -41,36 +32,36 @@ import unittest
|
|
|
41
32
|
|
|
42
33
|
import appier
|
|
43
34
|
|
|
44
|
-
class ConfigTest(unittest.TestCase):
|
|
45
35
|
|
|
36
|
+
class ConfigTest(unittest.TestCase):
|
|
46
37
|
def test_basic(self):
|
|
47
38
|
appier.conf_s("NAME", "name")
|
|
48
39
|
result = appier.conf("NAME")
|
|
49
40
|
|
|
50
41
|
self.assertEqual(result, "name")
|
|
51
42
|
|
|
52
|
-
result = appier.conf("NAME", cast
|
|
43
|
+
result = appier.conf("NAME", cast=str)
|
|
53
44
|
|
|
54
45
|
self.assertEqual(result, "name")
|
|
55
46
|
self.assertEqual(type(result), str)
|
|
56
47
|
|
|
57
|
-
result = appier.conf("NAME", cast
|
|
48
|
+
result = appier.conf("NAME", cast="str")
|
|
58
49
|
|
|
59
50
|
self.assertEqual(result, "name")
|
|
60
51
|
self.assertEqual(type(result), str)
|
|
61
52
|
|
|
62
53
|
appier.conf_s("AGE", "10")
|
|
63
|
-
result = appier.conf("AGE", cast
|
|
54
|
+
result = appier.conf("AGE", cast=int)
|
|
64
55
|
|
|
65
56
|
self.assertEqual(result, 10)
|
|
66
57
|
self.assertEqual(type(result), int)
|
|
67
58
|
|
|
68
|
-
result = appier.conf("AGE", cast
|
|
59
|
+
result = appier.conf("AGE", cast="int")
|
|
69
60
|
|
|
70
61
|
self.assertEqual(result, 10)
|
|
71
62
|
self.assertEqual(type(result), int)
|
|
72
63
|
|
|
73
|
-
result = appier.conf("AGE", cast
|
|
64
|
+
result = appier.conf("AGE", cast=str)
|
|
74
65
|
|
|
75
66
|
self.assertEqual(result, "10")
|
|
76
67
|
self.assertEqual(type(result), str)
|
|
@@ -81,10 +72,10 @@ class ConfigTest(unittest.TestCase):
|
|
|
81
72
|
|
|
82
73
|
def test_none(self):
|
|
83
74
|
appier.conf_s("AGE", None)
|
|
84
|
-
result = appier.conf("AGE", cast
|
|
75
|
+
result = appier.conf("AGE", cast=int)
|
|
85
76
|
|
|
86
77
|
self.assertEqual(result, None)
|
|
87
78
|
|
|
88
|
-
result = appier.conf("HEIGHT", cast
|
|
79
|
+
result = appier.conf("HEIGHT", cast=int)
|
|
89
80
|
|
|
90
81
|
self.assertEqual(result, None)
|
appier/test/crypt.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -41,8 +32,8 @@ import unittest
|
|
|
41
32
|
|
|
42
33
|
import appier
|
|
43
34
|
|
|
44
|
-
class CryptTest(unittest.TestCase):
|
|
45
35
|
|
|
36
|
+
class CryptTest(unittest.TestCase):
|
|
46
37
|
def test_rc4(self):
|
|
47
38
|
rc4 = appier.RC4(b"hello key")
|
|
48
39
|
result = rc4.encrypt(b"hello world")
|
appier/test/data.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -41,8 +32,8 @@ import unittest
|
|
|
41
32
|
|
|
42
33
|
import appier
|
|
43
34
|
|
|
44
|
-
class DataTest(unittest.TestCase):
|
|
45
35
|
|
|
36
|
+
class DataTest(unittest.TestCase):
|
|
46
37
|
def test_id(self):
|
|
47
38
|
adapter = appier.DataAdapter()
|
|
48
39
|
identifier = adapter._id()
|
appier/test/exceptions.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -41,31 +32,31 @@ import unittest
|
|
|
41
32
|
|
|
42
33
|
import appier
|
|
43
34
|
|
|
44
|
-
class ExceptionsTest(unittest.TestCase):
|
|
45
35
|
|
|
36
|
+
class ExceptionsTest(unittest.TestCase):
|
|
46
37
|
def test_encoding(self):
|
|
47
|
-
exception = appier.AppierException(message
|
|
38
|
+
exception = appier.AppierException(message="Olá Mundo")
|
|
48
39
|
self.assertEqual(str(exception), "Olá Mundo")
|
|
49
40
|
|
|
50
41
|
message_u = appier.legacy.u("Olá Mundo")
|
|
51
|
-
exception = appier.AppierException(message
|
|
42
|
+
exception = appier.AppierException(message=message_u)
|
|
52
43
|
self.assertEqual(str(exception), "Olá Mundo")
|
|
53
44
|
self.assertEqual(appier.legacy.UNICODE(exception), appier.legacy.u("Olá Mundo"))
|
|
54
45
|
|
|
55
46
|
def test_validation(self):
|
|
56
|
-
errors = dict(name
|
|
47
|
+
errors = dict(name=["is empty"])
|
|
57
48
|
error = appier.ValidationError(errors, object)
|
|
58
49
|
errors_s = error.errors_s()
|
|
59
50
|
|
|
60
51
|
self.assertEqual(errors_s, "name => is empty")
|
|
61
52
|
|
|
62
|
-
errors = dict(name
|
|
53
|
+
errors = dict(name=["Olá Mundo"])
|
|
63
54
|
error = appier.ValidationError(errors, object)
|
|
64
55
|
errors_s = error.errors_s()
|
|
65
56
|
|
|
66
57
|
self.assertEqual(errors_s, appier.legacy.u("name => Olá Mundo"))
|
|
67
58
|
|
|
68
|
-
errors = dict(name
|
|
59
|
+
errors = dict(name=[appier.legacy.u("Olá Mundo")])
|
|
69
60
|
error = appier.ValidationError(errors, object)
|
|
70
61
|
errors_s = error.errors_s()
|
|
71
62
|
|
appier/test/export.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -42,8 +33,8 @@ import unittest
|
|
|
42
33
|
|
|
43
34
|
import appier
|
|
44
35
|
|
|
45
|
-
class ExportTest(unittest.TestCase):
|
|
46
36
|
|
|
37
|
+
class ExportTest(unittest.TestCase):
|
|
47
38
|
def setUp(self):
|
|
48
39
|
self.app = appier.App()
|
|
49
40
|
|
|
@@ -54,20 +45,17 @@ class ExportTest(unittest.TestCase):
|
|
|
54
45
|
|
|
55
46
|
def test_import_single(self):
|
|
56
47
|
structure = {
|
|
57
|
-
"person:id"
|
|
58
|
-
"account:id"
|
|
48
|
+
"person:id": dict(_id="person:id", seq=11),
|
|
49
|
+
"account:id": dict(_id="account:id", seq=33),
|
|
59
50
|
}
|
|
60
51
|
data = json.dumps(structure)
|
|
61
52
|
data = appier.legacy.bytes(data)
|
|
62
53
|
|
|
63
54
|
adapter = appier.get_adapter()
|
|
64
|
-
manager = appier.ExportManager(
|
|
65
|
-
adapter,
|
|
66
|
-
multiple = self.app.resolve()
|
|
67
|
-
)
|
|
55
|
+
manager = appier.ExportManager(adapter, multiple=self.app.resolve())
|
|
68
56
|
|
|
69
57
|
collection = adapter.collection("counter")
|
|
70
|
-
manager._import_single(collection, data, key
|
|
58
|
+
manager._import_single(collection, data, key="_id")
|
|
71
59
|
|
|
72
60
|
values = collection.find()
|
|
73
61
|
values = [value for value in values]
|
|
@@ -75,7 +63,7 @@ class ExportTest(unittest.TestCase):
|
|
|
75
63
|
self.assertEqual(type(values), list)
|
|
76
64
|
self.assertEqual(len(values), 2)
|
|
77
65
|
|
|
78
|
-
value = collection.find_one(dict(_id
|
|
66
|
+
value = collection.find_one(dict(_id="person:id"))
|
|
79
67
|
|
|
80
68
|
self.assertEqual(value["seq"], 11)
|
|
81
69
|
|
|
@@ -84,27 +72,22 @@ class ExportTest(unittest.TestCase):
|
|
|
84
72
|
(
|
|
85
73
|
"person:id",
|
|
86
74
|
appier.legacy.bytes(
|
|
87
|
-
json.dumps(dict(_id
|
|
88
|
-
|
|
89
|
-
)
|
|
75
|
+
json.dumps(dict(_id="person:id", seq=11)), encoding="utf-8"
|
|
76
|
+
),
|
|
90
77
|
),
|
|
91
78
|
(
|
|
92
79
|
"account:id",
|
|
93
80
|
appier.legacy.bytes(
|
|
94
|
-
json.dumps(dict(_id
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
81
|
+
json.dumps(dict(_id="account:id", seq=33)), encoding="utf-8"
|
|
82
|
+
),
|
|
83
|
+
),
|
|
98
84
|
]
|
|
99
85
|
|
|
100
86
|
adapter = appier.get_adapter()
|
|
101
|
-
manager = appier.ExportManager(
|
|
102
|
-
adapter,
|
|
103
|
-
multiple = self.app.resolve()
|
|
104
|
-
)
|
|
87
|
+
manager = appier.ExportManager(adapter, multiple=self.app.resolve())
|
|
105
88
|
|
|
106
89
|
collection = adapter.collection("counter")
|
|
107
|
-
manager._import_multiple(collection, data, key
|
|
90
|
+
manager._import_multiple(collection, data, key="_id")
|
|
108
91
|
|
|
109
92
|
values = collection.find()
|
|
110
93
|
values = [value for value in values]
|
|
@@ -112,6 +95,6 @@ class ExportTest(unittest.TestCase):
|
|
|
112
95
|
self.assertEqual(type(values), list)
|
|
113
96
|
self.assertEqual(len(values), 2)
|
|
114
97
|
|
|
115
|
-
value = collection.find_one(dict(_id
|
|
98
|
+
value = collection.find_one(dict(_id="person:id"))
|
|
116
99
|
|
|
117
100
|
self.assertEqual(value["seq"], 11)
|
appier/test/graph.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
|
|
4
4
|
# Hive Appier Framework
|
|
5
|
-
# Copyright (c) 2008-
|
|
5
|
+
# Copyright (c) 2008-2024 Hive Solutions Lda.
|
|
6
6
|
#
|
|
7
7
|
# This file is part of Hive Appier Framework.
|
|
8
8
|
#
|
|
@@ -22,16 +22,7 @@
|
|
|
22
22
|
__author__ = "João Magalhães <joamag@hive.pt>"
|
|
23
23
|
""" The author(s) of the module """
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
""" The version of the module """
|
|
27
|
-
|
|
28
|
-
__revision__ = "$LastChangedRevision$"
|
|
29
|
-
""" The revision number of the module """
|
|
30
|
-
|
|
31
|
-
__date__ = "$LastChangedDate$"
|
|
32
|
-
""" The last change date of the module """
|
|
33
|
-
|
|
34
|
-
__copyright__ = "Copyright (c) 2008-2022 Hive Solutions Lda."
|
|
25
|
+
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
|
|
35
26
|
""" The copyright for the module """
|
|
36
27
|
|
|
37
28
|
__license__ = "Apache License, Version 2.0"
|
|
@@ -41,17 +32,10 @@ import unittest
|
|
|
41
32
|
|
|
42
33
|
import appier
|
|
43
34
|
|
|
44
|
-
class GraphTest(unittest.TestCase):
|
|
45
35
|
|
|
36
|
+
class GraphTest(unittest.TestCase):
|
|
46
37
|
def test__build_path(self):
|
|
47
|
-
prev = dict(
|
|
48
|
-
B = "A",
|
|
49
|
-
C = "A",
|
|
50
|
-
D = "B",
|
|
51
|
-
E = "D",
|
|
52
|
-
F = "D",
|
|
53
|
-
G = "E"
|
|
54
|
-
)
|
|
38
|
+
prev = dict(B="A", C="A", D="B", E="D", F="D", G="E")
|
|
55
39
|
|
|
56
40
|
path = appier.Graph._build_path(prev, "A", "F")
|
|
57
41
|
self.assertEqual(path, ["A", "B", "D", "F"])
|
|
@@ -61,10 +45,7 @@ class GraphTest(unittest.TestCase):
|
|
|
61
45
|
self.assertEqual(len(graph.edges), 0)
|
|
62
46
|
|
|
63
47
|
def test_create_with_argument(self):
|
|
64
|
-
graph = appier.Graph([
|
|
65
|
-
("A", "B"),
|
|
66
|
-
("B", "D", 20, True)
|
|
67
|
-
])
|
|
48
|
+
graph = appier.Graph([("A", "B"), ("B", "D", 20, True)])
|
|
68
49
|
self.assertEqual(len(graph.edges), 3)
|
|
69
50
|
|
|
70
51
|
def test_add_edges(self):
|
|
@@ -74,7 +55,7 @@ class GraphTest(unittest.TestCase):
|
|
|
74
55
|
("B", "D", 20),
|
|
75
56
|
("B", "C", 10, True),
|
|
76
57
|
("D", "F"),
|
|
77
|
-
("F", "D")
|
|
58
|
+
("F", "D"),
|
|
78
59
|
]
|
|
79
60
|
graph.add_edges(edges)
|
|
80
61
|
|
|
@@ -92,7 +73,7 @@ class GraphTest(unittest.TestCase):
|
|
|
92
73
|
("D", "F"),
|
|
93
74
|
("F", "D"),
|
|
94
75
|
(),
|
|
95
|
-
("A")
|
|
76
|
+
("A"),
|
|
96
77
|
]
|
|
97
78
|
graph.add_edges(edges)
|
|
98
79
|
|
|
@@ -107,20 +88,16 @@ class GraphTest(unittest.TestCase):
|
|
|
107
88
|
graph.add_edge("A", "B")
|
|
108
89
|
self.assertEqual(graph.edges["A"], [("B", 1)])
|
|
109
90
|
|
|
110
|
-
graph.add_edge("B", "D", cost
|
|
111
|
-
graph.add_edge("B", "C", cost
|
|
91
|
+
graph.add_edge("B", "D", cost=20)
|
|
92
|
+
graph.add_edge("B", "C", cost=10)
|
|
112
93
|
self.assertEqual(graph.edges["B"], [("D", 20), ("C", 10)])
|
|
113
94
|
|
|
114
|
-
graph.add_edge("D", "F", bidirectional
|
|
95
|
+
graph.add_edge("D", "F", bidirectional=True)
|
|
115
96
|
self.assertEqual(graph.edges["D"], [("F", 1)])
|
|
116
97
|
self.assertEqual(graph.edges["F"], [("D", 1)])
|
|
117
98
|
|
|
118
99
|
def test_disjktra_no_path(self):
|
|
119
|
-
graph = appier.Graph([
|
|
120
|
-
("A", "B"),
|
|
121
|
-
("B", "C"),
|
|
122
|
-
("F", "G")
|
|
123
|
-
])
|
|
100
|
+
graph = appier.Graph([("A", "B"), ("B", "C"), ("F", "G")])
|
|
124
101
|
|
|
125
102
|
path, cost = graph.dijkstra("C", "A")
|
|
126
103
|
self.assertEqual(path, [])
|
|
@@ -142,50 +119,40 @@ class GraphTest(unittest.TestCase):
|
|
|
142
119
|
self.assertEqual(cost, 0)
|
|
143
120
|
|
|
144
121
|
def test_dijkstra_simple(self):
|
|
145
|
-
graph = appier.Graph([
|
|
146
|
-
("A", "B"),
|
|
147
|
-
("B", "C")
|
|
148
|
-
])
|
|
122
|
+
graph = appier.Graph([("A", "B"), ("B", "C")])
|
|
149
123
|
|
|
150
124
|
path, cost = graph.dijkstra("A", "C")
|
|
151
125
|
self.assertEqual(path, ["A", "B", "C"])
|
|
152
126
|
self.assertEqual(cost, 2)
|
|
153
127
|
|
|
154
128
|
def test_dijkstra_costs(self):
|
|
155
|
-
graph = appier.Graph([
|
|
156
|
-
("A", "B"),
|
|
157
|
-
("B", "C", 10),
|
|
158
|
-
("B", "D", 4),
|
|
159
|
-
("D", "C", 5)
|
|
160
|
-
])
|
|
129
|
+
graph = appier.Graph([("A", "B"), ("B", "C", 10), ("B", "D", 4), ("D", "C", 5)])
|
|
161
130
|
|
|
162
131
|
path, cost = graph.dijkstra("A", "C")
|
|
163
132
|
self.assertEqual(path, ["A", "B", "D", "C"])
|
|
164
133
|
self.assertEqual(cost, 10)
|
|
165
134
|
|
|
166
135
|
def test_dijkstra_loop(self):
|
|
167
|
-
graph = appier.Graph([
|
|
168
|
-
("A", "B"),
|
|
169
|
-
("B", "B"),
|
|
170
|
-
("B", "C")
|
|
171
|
-
])
|
|
136
|
+
graph = appier.Graph([("A", "B"), ("B", "B"), ("B", "C")])
|
|
172
137
|
|
|
173
138
|
path, cost = graph.dijkstra("A", "C")
|
|
174
139
|
self.assertEqual(path, ["A", "B", "C"])
|
|
175
140
|
self.assertEqual(cost, 2)
|
|
176
141
|
|
|
177
142
|
def test_dijkstra_big(self):
|
|
178
|
-
graph = appier.Graph(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
143
|
+
graph = appier.Graph(
|
|
144
|
+
[
|
|
145
|
+
("A", "B", 2),
|
|
146
|
+
("A", "C", 6),
|
|
147
|
+
("B", "D", 5),
|
|
148
|
+
("C", "D", 8),
|
|
149
|
+
("D", "E", 10),
|
|
150
|
+
("D", "F", 15),
|
|
151
|
+
("E", "F", 6),
|
|
152
|
+
("E", "G", 2),
|
|
153
|
+
("F", "G", 6),
|
|
154
|
+
]
|
|
155
|
+
)
|
|
189
156
|
|
|
190
157
|
path, cost = graph.dijkstra("A", "A")
|
|
191
158
|
self.assertEqual(path, ["A"])
|