python-backpack 1.0.5__py3-none-any.whl → 2.0.0__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.
tests/test_json_utils.py DELETED
@@ -1,46 +0,0 @@
1
- # ----------------------------------------------------------------------------------------
2
- # Python-Backpack - TestUtils Tests
3
- # Maximiliano Rocamora / maxirocamora@gmail.com
4
- # https://github.com/MaxRocamora/python-backpack
5
- # ----------------------------------------------------------------------------------------
6
-
7
- import os
8
- import sys
9
- import unittest
10
-
11
- from backpack.folder_utils import remove_files_in_dir
12
- from backpack.json_utils import json_load, json_save
13
-
14
- mod_path = os.path.dirname(__file__)
15
- if mod_path not in sys.path:
16
- sys.path.append(mod_path)
17
-
18
- NO_FILE = os.path.join(mod_path, 'test_json', 'no_file.json')
19
- JSON_LOAD_FILE = os.path.join(mod_path, 'test_json', 'data.json')
20
- JSON_SAVE_FILE = os.path.join(mod_path, 'test_json', 'save', 'data_saved.json')
21
- BROKEN_JSON_FILE = os.path.join(mod_path, 'test_json', 'data_broken.json')
22
-
23
-
24
- class Test_Errors(unittest.TestCase):
25
-
26
- def test_json_load(self):
27
- data = json_load(JSON_LOAD_FILE)
28
- self.assertTrue(type(data), dict)
29
- self.assertTrue(data.get('user'), 'Max')
30
- self.assertRaises(OSError, json_load, NO_FILE)
31
- self.assertRaises(OSError, json_load, BROKEN_JSON_FILE)
32
-
33
- def test_json_save(self):
34
- data = {'name': 'max'}
35
- r = json_save(data, JSON_SAVE_FILE)
36
- self.assertTrue(r)
37
- # remove files
38
- remove_files_in_dir(os.path.dirname(JSON_SAVE_FILE))
39
- os.removedirs(os.path.dirname(JSON_SAVE_FILE))
40
-
41
- # force error
42
- self.assertFalse(json_save(unittest, JSON_SAVE_FILE))
43
-
44
-
45
- if __name__ == '__main__':
46
- unittest.main()
tests/test_jsonmd.py DELETED
@@ -1,90 +0,0 @@
1
- # ----------------------------------------------------------------------------------------
2
- # Python-Backpack - JsonMD Tests
3
- # Maximiliano Rocamora / maxirocamora@gmail.com
4
- # https://github.com/MaxRocamora/python-backpack
5
- # ----------------------------------------------------------------------------------------
6
-
7
- import contextlib
8
- from backpack.json_metadata import JsonMetaFile
9
-
10
- import unittest
11
- import os
12
- import sys
13
-
14
- mod_path = os.path.dirname(__file__)
15
- if mod_path not in sys.path:
16
- sys.path.append(mod_path)
17
-
18
-
19
- # test path & name
20
- TEST_PATH = os.path.join(mod_path, 'test_json')
21
- NAME = 'test'
22
- CLASS_NAME = 'proxy'
23
- ATTRIBUTES = ['foo', 'bar']
24
-
25
-
26
- class Test_windows(unittest.TestCase):
27
-
28
- @classmethod
29
- def tearDownClass(cls):
30
- # remove test files
31
- with contextlib.suppress(OSError):
32
- # os.remove(temp_update_json_test_file)
33
- # os.remove(test_json_file)
34
- pass
35
-
36
- def test_metadata(self):
37
- ''' testing module '''
38
- meta = JsonMetaFile(NAME, TEST_PATH)
39
-
40
- # test properties
41
- self.assertEqual(meta.name, NAME)
42
-
43
- meta.insert(key='coins', value=12)
44
-
45
- # check if data have coins and value 12
46
- self.assertEqual(meta._data['coins'], 12)
47
-
48
- meta.save()
49
-
50
- # file was created
51
- self.assertEqual(meta.has_file(), True)
52
-
53
- # check if file exists
54
- self.assertEqual(os.path.exists(meta.filepath), True)
55
-
56
- meta.insert('coins', 7)
57
-
58
- # check if data have coins and value 7
59
- self.assertEqual(meta._data['coins'], 7)
60
-
61
- meta.remove('coins')
62
- self.assertEqual(meta._data.get('coins', None), None)
63
-
64
- meta.insert(key='items', value=ATTRIBUTES)
65
- meta.save()
66
-
67
- # load
68
- metaObj = meta.load_as_class()
69
- self.assertEqual(type(metaObj), type)
70
- self.assertEqual(hasattr(metaObj, 'items'), True)
71
- self.assertEqual(metaObj.items, ATTRIBUTES)
72
-
73
- # load class
74
- meta = JsonMetaFile(NAME, TEST_PATH)
75
- meta.load()
76
-
77
- def test_create_from_class(self):
78
- ''' save_from_a_class '''
79
- meta = JsonMetaFile(NAME, TEST_PATH)
80
- self.assertEqual(meta.name, NAME)
81
-
82
- proxyClass = type('Proxy', (), {'foo': 12, 'items': ATTRIBUTES})
83
- meta.insert_class(proxyClass)
84
- self.assertEqual(meta._data['foo'], 12)
85
- self.assertEqual(meta._data['items'], ATTRIBUTES)
86
- meta.save()
87
-
88
-
89
- if __name__ == '__main__':
90
- unittest.main()
tests/test_misc.py DELETED
@@ -1,54 +0,0 @@
1
- # ----------------------------------------------------------------------------------------
2
- # Python-Backpack - Other Tests
3
- # Maximiliano Rocamora / maxirocamora@gmail.com
4
- # https://github.com/MaxRocamora/python-backpack
5
- # ----------------------------------------------------------------------------------------
6
-
7
- import os
8
- import sys
9
- import logging
10
- import unittest
11
-
12
- from backpack.logger import get_logger
13
- from backpack.patterns import Singleton
14
- from backpack.test_utils import random_string
15
- from backpack.version import app_name, version, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH
16
-
17
- mod_path = os.path.dirname(__file__)
18
- if mod_path not in sys.path:
19
- sys.path.append(mod_path)
20
-
21
-
22
- class UniqueClass(Singleton):
23
- def __init__(self) -> None:
24
- super().__init__()
25
-
26
-
27
- class Test_Errors(unittest.TestCase):
28
-
29
- @classmethod
30
- def tearDownClass(cls):
31
- pass
32
-
33
- def test_version(self):
34
- ''' testing module '''
35
- self.assertEqual(app_name, 'python-backpack')
36
- self.assertEqual(version, f'{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}')
37
-
38
- def test_logger(self):
39
- log = get_logger('test')
40
- self.assertEqual(log.name, 'test')
41
- self.assertEqual(log.level, logging.DEBUG)
42
-
43
- def test_singleton(self):
44
- ''' create a singleton twice and check attribute '''
45
- _singleton = UniqueClass()
46
- self.assertFalse(hasattr(_singleton, 'name'))
47
- _singleton.name = random_string(5)
48
- # create from singleton
49
- _singleton_b = UniqueClass()
50
- self.assertTrue(hasattr(_singleton_b, 'name'))
51
-
52
-
53
- if __name__ == '__main__':
54
- unittest.main()
tests/test_strings.py DELETED
@@ -1,94 +0,0 @@
1
- # ----------------------------------------------------------------------------------------
2
- # Python-Backpack - Strings UnitTest
3
- # Maximiliano Rocamora / maxirocamora@gmail.com
4
- # https://github.com/MaxRocamora/python-backpack
5
- # ----------------------------------------------------------------------------------------
6
-
7
- import os
8
- import sys
9
- import unittest
10
-
11
- from backpack.strings import has_numbers, begin_with_number, begin_or_end_with_numbers
12
- from backpack.strings import reformat_input_string, camelcase_to_snakecase
13
-
14
-
15
- mod_path = os.path.dirname(__file__)
16
- if mod_path not in sys.path:
17
- sys.path.append(mod_path)
18
-
19
- # Tests Constants
20
- HAS_NUMBERS_TRUE = 'blade1_runner'
21
- HAS_NUMBERS_FALSE = 'blade_runner'
22
- BEGIN_WITH_NUMBER_TRUE = '8blade_runner'
23
- BEGIN_WITH_NUMBER_FALSE = 'blade_runner'
24
- END_WITH_NUMBER_TRUE = 'blade_runner7'
25
-
26
-
27
- REFORMAT_RESULT = 'blade_runner'
28
- REFORMAT_REGEX = 'bla#de_runn$er'
29
- REFORMAT_SPACE = 'blade runner'
30
- REFORMAT_HYPHEN = 'blade-runner'
31
- REFORMAT_BOTH = 'blade runner-2049'
32
- REFORMAT_BOTH_RESULT = 'blade_runner_2049'
33
-
34
-
35
- class Test_Errors(unittest.TestCase):
36
-
37
- @classmethod
38
- def tearDownClass(cls):
39
- pass
40
-
41
- def test_has_numbers(self):
42
- ''' testing module '''
43
- self.assertEqual(has_numbers(HAS_NUMBERS_TRUE), True)
44
- self.assertEqual(has_numbers(HAS_NUMBERS_FALSE), False)
45
-
46
- def test_numbers(self):
47
- ''' testing module '''
48
- self.assertEqual(begin_with_number(BEGIN_WITH_NUMBER_TRUE), True)
49
- self.assertEqual(begin_with_number(BEGIN_WITH_NUMBER_FALSE), False)
50
-
51
- # no numbers on ends
52
- self.assertEqual(begin_or_end_with_numbers(HAS_NUMBERS_FALSE), False)
53
- # begin with number
54
- self.assertEqual(begin_or_end_with_numbers(BEGIN_WITH_NUMBER_TRUE), True)
55
- # end with number
56
- self.assertEqual(begin_or_end_with_numbers(END_WITH_NUMBER_TRUE), True)
57
-
58
- def test_reformat(self):
59
- ''' testing module '''
60
- self.assertEqual(reformat_input_string(REFORMAT_REGEX), REFORMAT_RESULT)
61
- self.assertEqual(reformat_input_string(REFORMAT_SPACE), REFORMAT_RESULT)
62
- self.assertEqual(reformat_input_string(REFORMAT_HYPHEN), REFORMAT_RESULT)
63
- self.assertEqual(reformat_input_string(REFORMAT_BOTH), REFORMAT_BOTH_RESULT)
64
- # only regex
65
- self.assertEqual(
66
- reformat_input_string(
67
- REFORMAT_BOTH, under_spaces=False, under_hyphen=False), REFORMAT_BOTH
68
- )
69
-
70
- def test_camelcase_to_snakecase(self):
71
-
72
- # Test case 1: Input with no uppercase characters
73
- input_str, expected_output = "nocamelcase", "nocamelcase"
74
- self.assertEqual(camelcase_to_snakecase(input_str), expected_output)
75
-
76
- # Test case 2: Input with single uppercase character
77
- input_str, expected_output = "OneCamelCaseChar", "one_camel_case_char"
78
- self.assertEqual(camelcase_to_snakecase(input_str), expected_output)
79
-
80
- # Test case 3: Input with multiple uppercase characters
81
- input_str, expected_output = "MultiCamelCaseString", "multi_camel_case_string"
82
- self.assertEqual(camelcase_to_snakecase(input_str), expected_output)
83
-
84
- # Test case 4: Input with leading and trailing underscores
85
- input_str, expected_output = "_CamelCase_", "_camel_case_"
86
- self.assertEqual(camelcase_to_snakecase(input_str), expected_output)
87
-
88
- # Test case 5: Input with leading and trailing underscores and lowercase
89
- input_str, expected_output = "_camel_Case_", "_camel_case_"
90
- self.assertEqual(camelcase_to_snakecase(input_str), expected_output)
91
-
92
-
93
- if __name__ == '__main__':
94
- unittest.main()
tests/test_test_utils.py DELETED
@@ -1,45 +0,0 @@
1
- # ----------------------------------------------------------------------------------------
2
- # Python-Backpack - TestUtils Tests
3
- # Maximiliano Rocamora / maxirocamora@gmail.com
4
- # https://github.com/MaxRocamora/python-backpack
5
- # ----------------------------------------------------------------------------------------
6
-
7
- import os
8
- import sys
9
- import time
10
- import unittest
11
-
12
- from backpack.test_utils import random_string
13
- from backpack.test_utils import time_function_decorator
14
-
15
- mod_path = os.path.dirname(__file__)
16
- if mod_path not in sys.path:
17
- sys.path.append(mod_path)
18
-
19
-
20
- @time_function_decorator
21
- def one_second_delay():
22
- ''' one second delay to test time_function_decorator '''
23
- time.sleep(1)
24
-
25
-
26
- class Test_Errors(unittest.TestCase):
27
-
28
- @classmethod
29
- def tearDownClass(cls):
30
- pass
31
-
32
- def test_random_string(self):
33
- ''' testing module '''
34
- r = random_string(10)
35
- self.assertEqual(len(r), 10)
36
- self.assertEqual(isinstance(r, str), True)
37
- r = random_string(0)
38
- self.assertEqual(len(r), 0)
39
-
40
- def test_delay(self):
41
- one_second_delay()
42
-
43
-
44
- if __name__ == '__main__':
45
- unittest.main()