inpsPyPI 1.0.1__tar.gz → 1.0.3__tar.gz
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.
- inpspypi-1.0.3/.gitignore +2 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/PKG-INFO +1 -1
- {inpspypi-1.0.1 → inpspypi-1.0.3}/__init__.py +8 -2
- {inpspypi-1.0.1 → inpspypi-1.0.3}/convert.py +2 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/pyproject.toml +1 -1
- inpspypi-1.0.3/test.py +12 -0
- inpspypi-1.0.3/test_all.py +441 -0
- inpspypi-1.0.1/test.py +0 -2
- {inpspypi-1.0.1 → inpspypi-1.0.3}/.github/workflows/build_inpsPyPI.yml +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/LICENSE +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/README.md +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/builder_for_flask_jsonify.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/check.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/cipher.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/dictionarily.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/easy_sql.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/excellent_reader.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/memory.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/simple_file_handler.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/sort.py +0 -0
- {inpspypi-1.0.1 → inpspypi-1.0.3}/stackily.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: inpsPyPI
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: PyPI package designed to make development in Python easier.
|
|
5
5
|
Project-URL: Homepage, https://github.com/isaiahnoelpulidosalazar/inpsPyPI
|
|
6
6
|
Author-email: Isaiah Noel Pulido Salazar <isaiahnoelpulidosalazar@gmail.com>
|
|
@@ -5,7 +5,13 @@ from .excellent_reader import get_n_column_from_sheet_index, get_first_column_fr
|
|
|
5
5
|
from .memory import Memory
|
|
6
6
|
from .test import test_method
|
|
7
7
|
from .sort import bubble_sort, cocktail_shaker_sort, odd_even_sort, selection_sort, insertion_sort, shellsort, quicksort, merge_sort, heapsort, introsort, timsort, counting_sort, bucket_sort_uniform, pigeonhole_sort, patience_sorting, bogosort, bead_sort
|
|
8
|
-
from .stackily import Stackily
|
|
8
|
+
from .stackily import Stackily
|
|
9
|
+
|
|
10
|
+
# To run unit tests, use the following command:
|
|
11
|
+
# python -m unittest test_all.py
|
|
12
|
+
|
|
13
|
+
# To run unit tests without print statements, use the following command:
|
|
14
|
+
# python -m unittest -b test_all.py
|
|
9
15
|
|
|
10
16
|
# changes:
|
|
11
|
-
# -
|
|
17
|
+
# - add internet connection check to test.py
|
inpspypi-1.0.3/test.py
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import os
|
|
3
|
+
import sqlite3
|
|
4
|
+
import io
|
|
5
|
+
from contextlib import redirect_stdout
|
|
6
|
+
|
|
7
|
+
import openpyxl
|
|
8
|
+
|
|
9
|
+
from builder_for_flask_jsonify import bake, JSON_RESPONSE_TITLE
|
|
10
|
+
from check import Check
|
|
11
|
+
from cipher import Cipher
|
|
12
|
+
from convert import Convert
|
|
13
|
+
from dictionarily import Dictionarily
|
|
14
|
+
from easy_sql import EasySQL
|
|
15
|
+
from excellent_reader import (
|
|
16
|
+
get_n_column_from_sheet_index,
|
|
17
|
+
get_first_column_from_sheet_index,
|
|
18
|
+
get_n_column_from_all_sheets,
|
|
19
|
+
get_first_column_from_all_sheets,
|
|
20
|
+
set_n_column_from_sheet_index,
|
|
21
|
+
set_first_column_from_sheet_index,
|
|
22
|
+
set_n_column_from_all_sheets,
|
|
23
|
+
set_first_column_from_all_sheets,
|
|
24
|
+
)
|
|
25
|
+
from memory import Memory
|
|
26
|
+
from simple_file_handler import SimpleFileHandler
|
|
27
|
+
from sort import (
|
|
28
|
+
bubble_sort,
|
|
29
|
+
cocktail_shaker_sort,
|
|
30
|
+
odd_even_sort,
|
|
31
|
+
selection_sort,
|
|
32
|
+
insertion_sort,
|
|
33
|
+
shellsort,
|
|
34
|
+
quicksort,
|
|
35
|
+
merge_sort,
|
|
36
|
+
heapsort,
|
|
37
|
+
introsort,
|
|
38
|
+
timsort,
|
|
39
|
+
counting_sort,
|
|
40
|
+
bucket_sort_uniform,
|
|
41
|
+
pigeonhole_sort,
|
|
42
|
+
patience_sorting,
|
|
43
|
+
bogosort,
|
|
44
|
+
bead_sort,
|
|
45
|
+
)
|
|
46
|
+
from stackily import Stackily
|
|
47
|
+
from test import test_method
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class TestBuilderForFlaskJsonify(unittest.TestCase):
|
|
51
|
+
def test_bake_string(self):
|
|
52
|
+
result = bake("Hello World")
|
|
53
|
+
self.assertEqual(result, {JSON_RESPONSE_TITLE: "Hello World"})
|
|
54
|
+
|
|
55
|
+
def test_bake_dict(self):
|
|
56
|
+
data = {"status": "success", "code": 200}
|
|
57
|
+
result = bake(data)
|
|
58
|
+
self.assertEqual(result, {JSON_RESPONSE_TITLE: data})
|
|
59
|
+
|
|
60
|
+
def test_bake_integer(self):
|
|
61
|
+
result = bake(12345)
|
|
62
|
+
self.assertEqual(result, {JSON_RESPONSE_TITLE: 12345})
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class TestCheck(unittest.TestCase):
|
|
66
|
+
def setUp(self):
|
|
67
|
+
Check.Email.valid_domain_names = []
|
|
68
|
+
Check.Email.valid_domain_extensions = []
|
|
69
|
+
Check.Email.valid_domains = []
|
|
70
|
+
Check.Email._should_use_full_domain = False
|
|
71
|
+
|
|
72
|
+
def test_email_partial_domain_validation(self):
|
|
73
|
+
Check.Email.add_valid_domain_name("gmail")
|
|
74
|
+
Check.Email.add_valid_domain_extension("com")
|
|
75
|
+
Check.Email.should_use_full_domain(False)
|
|
76
|
+
|
|
77
|
+
self.assertTrue(Check.Email.is_valid("user@gmail.com"))
|
|
78
|
+
self.assertFalse(Check.Email.is_valid("user@yahoo.com"))
|
|
79
|
+
self.assertFalse(Check.Email.is_valid("user@gmail"))
|
|
80
|
+
self.assertFalse(Check.Email.is_valid("invalid_email"))
|
|
81
|
+
|
|
82
|
+
def test_email_full_domain_validation(self):
|
|
83
|
+
Check.Email.add_valid_domain("yahoo.com")
|
|
84
|
+
Check.Email.should_use_full_domain(True)
|
|
85
|
+
|
|
86
|
+
self.assertTrue(Check.Email.is_valid("user@yahoo.com"))
|
|
87
|
+
self.assertFalse(Check.Email.is_valid("user@gmail.com"))
|
|
88
|
+
self.assertFalse(Check.Email.is_valid("user@yahoo.org"))
|
|
89
|
+
self.assertFalse(Check.Email.is_valid("invalid_email"))
|
|
90
|
+
|
|
91
|
+
def test_is_a_valid_philippine_mobile_number(self):
|
|
92
|
+
self.assertTrue(Check.is_a_valid_philippine_mobile_number("09171234567"))
|
|
93
|
+
self.assertTrue(Check.is_a_valid_philippine_mobile_number("+639171234567"))
|
|
94
|
+
self.assertTrue(Check.is_a_valid_philippine_mobile_number("639171234567"))
|
|
95
|
+
self.assertTrue(Check.is_a_valid_philippine_mobile_number(" (0917) 123-4567 "))
|
|
96
|
+
|
|
97
|
+
self.assertFalse(Check.is_a_valid_philippine_mobile_number("08171234567"))
|
|
98
|
+
self.assertFalse(Check.is_a_valid_philippine_mobile_number("091712345"))
|
|
99
|
+
self.assertFalse(Check.is_a_valid_philippine_mobile_number("091712345678"))
|
|
100
|
+
self.assertFalse(Check.is_a_valid_philippine_mobile_number("0917abc4567"))
|
|
101
|
+
|
|
102
|
+
def test_is_all_numbers(self):
|
|
103
|
+
self.assertTrue(Check.is_all_numbers("123456"))
|
|
104
|
+
self.assertFalse(Check.is_all_numbers("123a45"))
|
|
105
|
+
self.assertTrue(Check.is_all_numbers(""))
|
|
106
|
+
|
|
107
|
+
def test_has_numbers(self):
|
|
108
|
+
self.assertTrue(Check.has_numbers("abc1"))
|
|
109
|
+
self.assertFalse(Check.has_numbers("abc"))
|
|
110
|
+
self.assertFalse(Check.has_numbers(""))
|
|
111
|
+
|
|
112
|
+
def test_has_symbols(self):
|
|
113
|
+
self.assertTrue(Check.has_symbols("hello!"))
|
|
114
|
+
self.assertFalse(Check.has_symbols("hello"))
|
|
115
|
+
self.assertFalse(Check.has_symbols(""))
|
|
116
|
+
|
|
117
|
+
def test_has_spaces(self):
|
|
118
|
+
self.assertTrue(Check.has_spaces("hello world"))
|
|
119
|
+
self.assertFalse(Check.has_spaces("helloworld"))
|
|
120
|
+
self.assertFalse(Check.has_spaces(""))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class TestCipher(unittest.TestCase):
|
|
124
|
+
def test_transposition_cipher(self):
|
|
125
|
+
self.assertEqual(Cipher.transposition_cipher("HELLO WORLD"), "HLOOLELWRD")
|
|
126
|
+
self.assertEqual(Cipher.transposition_cipher("1234"), "1324")
|
|
127
|
+
|
|
128
|
+
def test_giovanni_cipher(self):
|
|
129
|
+
self.assertEqual(Cipher.giovanni_cipher("HELLO WORLD", "KEYWORD", "C"), "RYCCH SHLCE")
|
|
130
|
+
self.assertEqual(Cipher.giovanni_cipher("HELLO, WORLD!", "KEYWORD", "C"), "RYCCH, SHLCE!")
|
|
131
|
+
|
|
132
|
+
def test_keyword_cipher(self):
|
|
133
|
+
self.assertEqual(Cipher.keyword_cipher("HELLO WORLD", "KEYWORD"), "AOGGJ UJNGW")
|
|
134
|
+
self.assertEqual(Cipher.keyword_cipher("HELLO, WORLD!", "KEYWORD"), "AOGGJ, UJNGW!")
|
|
135
|
+
|
|
136
|
+
def test_caesar_cipher(self):
|
|
137
|
+
self.assertEqual(Cipher.caesar_cipher("HELLO WORLD", 3), "KHOOR ZRUOG")
|
|
138
|
+
self.assertEqual(Cipher.caesar_cipher("HELLO, WORLD!", 3), "KHOOR, ZRUOG!")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class TestConvert(unittest.TestCase):
|
|
142
|
+
def test_reverse(self):
|
|
143
|
+
self.assertEqual(Convert.reverse("python"), "nohtyp")
|
|
144
|
+
self.assertEqual(Convert.reverse(""), "")
|
|
145
|
+
|
|
146
|
+
def test_base64_conversions(self):
|
|
147
|
+
encoded = Convert.to_base64("hello")
|
|
148
|
+
self.assertEqual(encoded, "aGVsbG8=")
|
|
149
|
+
decoded = Convert.from_base64("aGVsbG8=")
|
|
150
|
+
self.assertEqual(decoded, "hello")
|
|
151
|
+
|
|
152
|
+
def test_byte_array_conversions(self):
|
|
153
|
+
self.assertEqual(Convert.to_byte_array("hello"), b"hello")
|
|
154
|
+
self.assertEqual(Convert.from_byte_array(b"hello"), "hello")
|
|
155
|
+
|
|
156
|
+
def test_hex_conversions(self):
|
|
157
|
+
encoded = Convert.to_hex("hello")
|
|
158
|
+
self.assertEqual(encoded, "68656C6C6F")
|
|
159
|
+
self.assertEqual(Convert.from_hex("68656C6C6F"), "hello")
|
|
160
|
+
|
|
161
|
+
def test_binary_conversions(self):
|
|
162
|
+
encoded = Convert.to_binary("hello")
|
|
163
|
+
self.assertEqual(encoded, "0110100001100101011011000110110001101111")
|
|
164
|
+
self.assertEqual(Convert.from_binary("0110100001100101011011000110110001101111"), "hello")
|
|
165
|
+
|
|
166
|
+
def test_numeric_conversions(self):
|
|
167
|
+
self.assertEqual(Convert.to_int("100"), 100)
|
|
168
|
+
self.assertEqual(Convert.to_double("3.14"), 3.14)
|
|
169
|
+
self.assertEqual(Convert.to_long("100000"), 100000)
|
|
170
|
+
self.assertEqual(Convert.to_float("3.14"), 3.14)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class TestDictionarily(unittest.TestCase):
|
|
174
|
+
def test_add_and_show(self):
|
|
175
|
+
d = Dictionarily()
|
|
176
|
+
d.add("key1", "value1")
|
|
177
|
+
self.assertEqual(d.show(), {"key1": "value1"})
|
|
178
|
+
|
|
179
|
+
def test_sort(self):
|
|
180
|
+
d = Dictionarily()
|
|
181
|
+
d.add("b", 2)
|
|
182
|
+
d.add("a", 1)
|
|
183
|
+
d.sort()
|
|
184
|
+
self.assertEqual(list(d.show().keys()), ["a", "b"])
|
|
185
|
+
|
|
186
|
+
def test_sort_numbers_first(self):
|
|
187
|
+
d = Dictionarily()
|
|
188
|
+
d.add("b", 2)
|
|
189
|
+
d.add("a", 1)
|
|
190
|
+
d.add(2, "two")
|
|
191
|
+
d.add(1, "one")
|
|
192
|
+
d.sort_numbers_first()
|
|
193
|
+
self.assertEqual(list(d.show().keys()), [1, 2, "a", "b"])
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class TestEasySQL(unittest.TestCase):
|
|
197
|
+
def setUp(self):
|
|
198
|
+
self.db_name = "test_database"
|
|
199
|
+
self.db_filename = f"{self.db_name}.db"
|
|
200
|
+
self.sql = EasySQL(self.db_name)
|
|
201
|
+
|
|
202
|
+
def tearDown(self):
|
|
203
|
+
if os.path.exists(self.db_filename):
|
|
204
|
+
try:
|
|
205
|
+
os.remove(self.db_filename)
|
|
206
|
+
except PermissionError:
|
|
207
|
+
pass
|
|
208
|
+
|
|
209
|
+
def test_database_crud_operations(self):
|
|
210
|
+
self.sql.create_table("users", {"id": "INTEGER PRIMARY KEY", "name": "TEXT"})
|
|
211
|
+
|
|
212
|
+
self.sql.insert_to_table("users", {"id": 1, "name": "Alice"})
|
|
213
|
+
self.sql.insert_to_table("users", {"id": 2, "name": "Bob"})
|
|
214
|
+
|
|
215
|
+
rows = self.sql.get_table_values("users")
|
|
216
|
+
self.assertEqual(len(rows), 2)
|
|
217
|
+
self.assertEqual(rows[0], (1, "Alice"))
|
|
218
|
+
self.assertEqual(rows[1], (2, "Bob"))
|
|
219
|
+
|
|
220
|
+
self.sql.delete_from_table("users", {"id": 1})
|
|
221
|
+
rows = self.sql.get_table_values("users")
|
|
222
|
+
self.assertEqual(len(rows), 1)
|
|
223
|
+
self.assertEqual(rows[0], (2, "Bob"))
|
|
224
|
+
|
|
225
|
+
self.sql.clear_table("users")
|
|
226
|
+
rows = self.sql.get_table_values("users")
|
|
227
|
+
self.assertEqual(len(rows), 0)
|
|
228
|
+
|
|
229
|
+
self.sql.delete_table("users")
|
|
230
|
+
with self.assertRaises(sqlite3.OperationalError):
|
|
231
|
+
self.sql.get_table_values("users")
|
|
232
|
+
|
|
233
|
+
def test_print_table(self):
|
|
234
|
+
self.sql.create_table("users", {"id": "INTEGER PRIMARY KEY", "name": "TEXT"})
|
|
235
|
+
|
|
236
|
+
f_empty = io.StringIO()
|
|
237
|
+
with redirect_stdout(f_empty):
|
|
238
|
+
self.sql.print_table("users")
|
|
239
|
+
self.assertIn("Table 'users' is empty.", f_empty.getvalue())
|
|
240
|
+
|
|
241
|
+
self.sql.insert_to_table("users", {"id": 1, "name": "Alice"})
|
|
242
|
+
f_populated = io.StringIO()
|
|
243
|
+
with redirect_stdout(f_populated):
|
|
244
|
+
self.sql.print_table("users")
|
|
245
|
+
self.assertIn("(1, 'Alice')", f_populated.getvalue())
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class TestExcellentReader(unittest.TestCase):
|
|
249
|
+
def setUp(self):
|
|
250
|
+
self.filename = "test_sheet.xlsx"
|
|
251
|
+
wb = openpyxl.Workbook()
|
|
252
|
+
ws1 = wb.active
|
|
253
|
+
ws1.title = "SheetA"
|
|
254
|
+
ws2 = wb.create_sheet("SheetB")
|
|
255
|
+
|
|
256
|
+
ws1.append(["Header1"])
|
|
257
|
+
ws1.append(["Header2"])
|
|
258
|
+
ws1.append(["ValA3"])
|
|
259
|
+
ws1.append(["ValA4"])
|
|
260
|
+
|
|
261
|
+
ws2.append(["HeaderX"])
|
|
262
|
+
ws2.append(["HeaderY"])
|
|
263
|
+
ws2.append(["ValB3"])
|
|
264
|
+
ws2.append(["ValB4"])
|
|
265
|
+
|
|
266
|
+
wb.save(self.filename)
|
|
267
|
+
|
|
268
|
+
def tearDown(self):
|
|
269
|
+
if os.path.exists(self.filename):
|
|
270
|
+
try:
|
|
271
|
+
os.remove(self.filename)
|
|
272
|
+
except PermissionError:
|
|
273
|
+
pass
|
|
274
|
+
|
|
275
|
+
def test_get_first_column_from_sheet_index(self):
|
|
276
|
+
data = get_first_column_from_sheet_index(self.filename, 0, skip_rows=2)
|
|
277
|
+
self.assertEqual(data, {"SHEETA": ["VALA3", "VALA4"]})
|
|
278
|
+
|
|
279
|
+
def test_get_first_column_from_all_sheets(self):
|
|
280
|
+
data = get_first_column_from_all_sheets(self.filename, skip_rows=2)
|
|
281
|
+
self.assertEqual(data, {
|
|
282
|
+
"SHEETA": ["VALA3", "VALA4"],
|
|
283
|
+
"SHEETB": ["VALB3", "VALB4"]
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
def test_get_n_column_from_sheet_index(self):
|
|
287
|
+
data = get_n_column_from_sheet_index(self.filename, 0, 'A', skip_rows=2)
|
|
288
|
+
self.assertEqual(data, {"SHEETA": ["VALA3", "VALA4"]})
|
|
289
|
+
|
|
290
|
+
def test_set_n_column_from_sheet_index_list(self):
|
|
291
|
+
success = set_n_column_from_sheet_index(self.filename, 0, 'B', ["NewB3", "NewB4"], skip_rows=2)
|
|
292
|
+
self.assertTrue(success)
|
|
293
|
+
|
|
294
|
+
data = get_n_column_from_sheet_index(self.filename, 0, 'B', skip_rows=2)
|
|
295
|
+
self.assertEqual(data, {"SHEETA": ["NEWB3", "NEWB4"]})
|
|
296
|
+
|
|
297
|
+
def test_set_first_column_from_sheet_index_single_value(self):
|
|
298
|
+
success = set_first_column_from_sheet_index(self.filename, 0, "Single", skip_rows=2)
|
|
299
|
+
self.assertTrue(success)
|
|
300
|
+
|
|
301
|
+
data = get_first_column_from_sheet_index(self.filename, 0, skip_rows=2)
|
|
302
|
+
self.assertEqual(data, {"SHEETA": ["SINGLE", "SINGLE"]})
|
|
303
|
+
|
|
304
|
+
def test_set_first_column_from_all_sheets(self):
|
|
305
|
+
success = set_first_column_from_all_sheets(self.filename, "AllSheets", skip_rows=2)
|
|
306
|
+
self.assertTrue(success)
|
|
307
|
+
|
|
308
|
+
data = get_first_column_from_all_sheets(self.filename, skip_rows=2)
|
|
309
|
+
self.assertEqual(data, {
|
|
310
|
+
"SHEETA": ["ALLSHEETS", "ALLSHEETS"],
|
|
311
|
+
"SHEETB": ["ALLSHEETS", "ALLSHEETS"]
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
def test_file_not_found(self):
|
|
315
|
+
self.assertIsNone(get_first_column_from_sheet_index("nonexistent.xlsx", 0))
|
|
316
|
+
self.assertFalse(set_first_column_from_sheet_index("nonexistent.xlsx", 0, "Val"))
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class TestMemory(unittest.TestCase):
|
|
320
|
+
def setUp(self):
|
|
321
|
+
self.memory = Memory()
|
|
322
|
+
|
|
323
|
+
def test_memory_lifecycle(self):
|
|
324
|
+
self.assertEqual(self.memory.count(), 0)
|
|
325
|
+
|
|
326
|
+
self.memory.add("data1")
|
|
327
|
+
self.memory.add("data2")
|
|
328
|
+
self.assertEqual(self.memory.count(), 2)
|
|
329
|
+
|
|
330
|
+
self.assertTrue(self.memory.contains("data1"))
|
|
331
|
+
self.assertFalse(self.memory.contains("data3"))
|
|
332
|
+
|
|
333
|
+
self.assertEqual(self.memory.get(0), "data1")
|
|
334
|
+
self.assertEqual(self.memory.get(1), "data2")
|
|
335
|
+
|
|
336
|
+
self.memory.remove("data1")
|
|
337
|
+
self.assertEqual(self.memory.count(), 1)
|
|
338
|
+
self.assertFalse(self.memory.contains("data1"))
|
|
339
|
+
|
|
340
|
+
self.memory.add("data3")
|
|
341
|
+
self.memory.remove_at(0)
|
|
342
|
+
self.assertEqual(self.memory.get(0), "data3")
|
|
343
|
+
|
|
344
|
+
self.memory.clear()
|
|
345
|
+
self.assertEqual(self.memory.count(), 0)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
class TestSimpleFileHandler(unittest.TestCase):
|
|
349
|
+
def setUp(self):
|
|
350
|
+
self.filepath = "temp_text_file.txt"
|
|
351
|
+
|
|
352
|
+
def tearDown(self):
|
|
353
|
+
if os.path.exists(self.filepath):
|
|
354
|
+
try:
|
|
355
|
+
os.remove(self.filepath)
|
|
356
|
+
except PermissionError:
|
|
357
|
+
pass
|
|
358
|
+
|
|
359
|
+
def test_file_operations(self):
|
|
360
|
+
SimpleFileHandler.write(self.filepath, "hello")
|
|
361
|
+
self.assertTrue(os.path.exists(self.filepath))
|
|
362
|
+
|
|
363
|
+
content = SimpleFileHandler.read(self.filepath)
|
|
364
|
+
self.assertEqual(content, "hello")
|
|
365
|
+
|
|
366
|
+
SimpleFileHandler.append(self.filepath, " world")
|
|
367
|
+
content = SimpleFileHandler.read(self.filepath)
|
|
368
|
+
self.assertEqual(content, "hello world")
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
class TestSort(unittest.TestCase):
|
|
372
|
+
def test_sorting_algorithms(self):
|
|
373
|
+
arr = [5, 2, 9, 1, 5, 6]
|
|
374
|
+
expected = sorted(arr)
|
|
375
|
+
|
|
376
|
+
self.assertEqual(bubble_sort(list(arr)), expected)
|
|
377
|
+
self.assertEqual(cocktail_shaker_sort(list(arr)), expected)
|
|
378
|
+
self.assertEqual(odd_even_sort(list(arr)), expected)
|
|
379
|
+
self.assertEqual(selection_sort(list(arr)), expected)
|
|
380
|
+
self.assertEqual(insertion_sort(list(arr)), expected)
|
|
381
|
+
self.assertEqual(shellsort(list(arr)), expected)
|
|
382
|
+
self.assertEqual(quicksort(list(arr)), expected)
|
|
383
|
+
self.assertEqual(merge_sort(list(arr)), expected)
|
|
384
|
+
self.assertEqual(heapsort(list(arr)), expected)
|
|
385
|
+
self.assertEqual(introsort(list(arr)), expected)
|
|
386
|
+
self.assertEqual(timsort(list(arr)), expected)
|
|
387
|
+
self.assertEqual(pigeonhole_sort(list(arr)), expected)
|
|
388
|
+
self.assertEqual(patience_sorting(list(arr)), expected)
|
|
389
|
+
|
|
390
|
+
def test_counting_sort(self):
|
|
391
|
+
arr = [5, 2, 9, 1, 5, 6]
|
|
392
|
+
expected = sorted(arr)
|
|
393
|
+
self.assertEqual(counting_sort(list(arr)), expected)
|
|
394
|
+
self.assertEqual(counting_sort([]), [])
|
|
395
|
+
|
|
396
|
+
def test_bucket_sort_uniform(self):
|
|
397
|
+
arr = [0.5, 0.1, 0.9, 0.2, 0.7]
|
|
398
|
+
expected = sorted(arr)
|
|
399
|
+
self.assertEqual(bucket_sort_uniform(arr), expected)
|
|
400
|
+
|
|
401
|
+
def test_bogosort(self):
|
|
402
|
+
self.assertEqual(bogosort([2, 1]), [1, 2])
|
|
403
|
+
|
|
404
|
+
def test_bead_sort(self):
|
|
405
|
+
arr = [5, 2, 9, 1, 5, 6]
|
|
406
|
+
expected = sorted(arr)
|
|
407
|
+
self.assertEqual(bead_sort(list(arr)), expected)
|
|
408
|
+
|
|
409
|
+
with self.assertRaises(ValueError):
|
|
410
|
+
bead_sort([-1, 2])
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
class TestStackily(unittest.TestCase):
|
|
414
|
+
def setUp(self):
|
|
415
|
+
self.stack = Stackily()
|
|
416
|
+
|
|
417
|
+
def test_stack_operations(self):
|
|
418
|
+
self.assertTrue(self.stack.is_empty())
|
|
419
|
+
self.assertEqual(self.stack.size(), 0)
|
|
420
|
+
|
|
421
|
+
self.stack.push("item1")
|
|
422
|
+
self.stack.push("item2")
|
|
423
|
+
self.assertFalse(self.stack.is_empty())
|
|
424
|
+
self.assertEqual(self.stack.size(), 2)
|
|
425
|
+
|
|
426
|
+
self.assertEqual(self.stack.peek(), "item2")
|
|
427
|
+
|
|
428
|
+
self.stack.pop()
|
|
429
|
+
self.assertEqual(self.stack.size(), 1)
|
|
430
|
+
self.assertEqual(self.stack.peek(), "item1")
|
|
431
|
+
|
|
432
|
+
self.assertEqual(self.stack.to_list(), ["item1"])
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
class TestTest(unittest.TestCase):
|
|
436
|
+
def test_test_method(self):
|
|
437
|
+
self.assertEqual(test_method(), "Test method")
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
if __name__ == "__main__":
|
|
441
|
+
unittest.main()
|
inpspypi-1.0.1/test.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|