ciocore 9.1.0b2__py2.py3-none-any.whl → 9.1.0rc2__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.

Potentially problematic release.


This version of ciocore might be problematic. Click here for more details.

tests/test_data.py CHANGED
@@ -1,163 +1,173 @@
1
- """ test data
2
-
3
- isort:skip_file
4
- """
5
-
6
1
  import unittest
2
+ from unittest.mock import patch
3
+ from ciocore import data as coredata
7
4
 
8
- try:
9
- from unittest import mock
10
- except ImportError:
11
- import mock
12
-
13
- from ciocore import data
14
-
15
-
16
- from project_fixtures import PROJECTS
17
- from package_fixtures import SOFTWARE_DATA
18
- from instance_type_fixtures import LIN_INSTANCE_TYPES, ALL_INSTANCE_TYPES
19
-
20
- class TestDataAllInstanceTypes(unittest.TestCase):
5
+ class TestCoreData(unittest.TestCase):
21
6
  def setUp(self):
22
- self.default_cache = {
23
- "projects": PROJECTS,
24
- "instance_types": ALL_INSTANCE_TYPES,
25
- "packages": SOFTWARE_DATA,
7
+ """Set up test fixtures before each test method."""
8
+ self.mock_api_responses = {
9
+ 'projects': ['ProjectA', 'ProjectB'],
10
+ 'instance_types': [
11
+ {'operating_system': 'windows', 'name': 'win_machine', 'cores': 1, 'memory': '1024'},
12
+ {'operating_system': 'linux', 'name': 'linux_machine', 'cores': 1, 'memory': '1024'}
13
+ ],
14
+ 'software': [ # Added package_id to each package
15
+ {
16
+ 'name': 'maya-io',
17
+ 'version': '2022',
18
+ 'platform': 'windows',
19
+ 'product': 'maya-io',
20
+ 'package_id': '123456789'
21
+ },
22
+ {
23
+ 'name': 'maya-io',
24
+ 'version': '2022',
25
+ 'platform': 'linux',
26
+ 'product': 'maya-io',
27
+ 'package_id': '123456780'
28
+ },
29
+ {
30
+ 'name': 'nuke',
31
+ 'version': '13.0',
32
+ 'platform': 'linux',
33
+ 'product': 'nuke',
34
+ 'package_id': '123456781'
35
+ }
36
+ ],
37
+ 'extra_env': ['PATH=/custom/path', 'LICENSE_SERVER=1234']
26
38
  }
27
-
28
- # self.get_data_patcher = mock.patch.object(DataCache, "get_data", return_value=self.default_cache)
29
-
30
- # self.account_id_patcher = mock.patch(
31
- # "ciocore.data.get_account_id", return_value="1234"
32
- # )
33
-
34
- # self.mock_get_data = self.get_data_patcher.start()
35
- # self.mock_account_id = self.account_id_patcher.start()
36
-
37
- data.__data__ = {}
38
- data.__products__ = None
39
+ # Clear data before each test
40
+ coredata.clear()
39
41
 
40
42
  def tearDown(self):
41
- # self.get_data_patcher.stop()
42
- # self.account_id_patcher.stop()
43
- pass
44
-
45
- # def override_default_cache(self, **kwargs):
46
- # return_val = {}
47
- # return_val.update(self.default_cache)
48
- # return_val.update(kwargs)
49
- # self.mock_get_data.return_value = return_val
50
-
51
- # def test_smoke(self):
52
- # self.assertEqual(1, 1)
53
-
54
- # def test_init_empty_projects_global(self):
55
- # data.init()
56
- # self.assertEqual(data.products(), [])
57
-
58
- # def test_init_stores_all_args(self):
59
- # data.init("a", "b", "c")
60
- # self.assertEqual(data.products(), ["a", "b", "c"])
61
-
62
- # def test_data_raises_if_not_initialized(self):
63
- # with self.assertRaises(ValueError):
64
- # data.data()
65
-
66
- # def test_valid(self):
67
- # self.assertEqual(data.valid(), False)
68
- # data.init()
69
- # data.data()
70
- # self.assertEqual(data.valid(), True)
71
-
72
- # def test_clear(self):
73
- # data.init()
74
- # data.data()
75
- # self.assertEqual(data.valid(), True)
76
- # data.clear()
77
- # self.assertEqual(data.valid(), False)
78
-
79
- # def test_does_not_refresh_if_not_force(self):
80
- # data.init()
81
- # p1 = data.data()["projects"]
82
- # self.assertEqual(len(p1), 4)
83
- # # merge the default cache with a new projects list containing only two projects
84
- # # self.override_default_cache(projects=["a", "b"])
85
- # p2 = data.data()["projects"]
86
- # self.assertEqual(p2, p1)
87
-
88
- # def test_does_refresh_if_force_all(self):
89
- # data.init()
90
- # p1 = data.data()["projects"]
91
- # self.assertEqual(len(p1), 4)
92
- # # self.override_default_cache(projects=["a", "b"])
93
- # p2 = data.data(force=True)["projects"]
94
- # self.assertNotEqual(p2, p1)
95
- # self.assertEqual(len(p2), 2)
96
-
97
- # def test_get_data_for_one_product(self):
98
- # data.init("c4d")
99
- # # inst = data.data()["instance_types"]
100
- # sw = data.data()["software"]
101
- # self.assertEqual(len(sw.supported_host_names()), 2)
102
-
103
- # def test_several_products(self):
104
- # data.init("c4d", "maya")
105
- # sw = data.data()["software"]
106
- # self.assertEqual(len(sw.supported_host_names()), 5)
107
-
108
- # def test_one_product_can_be_a_plugin(self):
109
- # data.init("redshift")
110
- # sw = data.data()["software"]
111
- # self.assertEqual(len(sw.supported_host_names()), 4)
112
-
113
- # def test_several_products_ignore_plugins(self):
114
- # data.init("redshift", "c4d")
115
- # sw = data.data()["software"]
116
- # self.assertEqual(len(sw.supported_host_names()), 2)
117
-
118
- # def test_linux_only_instance_types(self):
119
- # # self.override_default_cache(instance_types=LIN_INSTANCE_TYPES)
120
- # data.init()
121
- # h = data.data()["instance_types"]
122
- # self.assertEqual(len(h.instance_types.keys()), 4)
123
-
124
- # def test_linux_only_packages_when_linux_only_instance_types(self):
125
- # # self.override_default_cache(instance_types=LIN_INSTANCE_TYPES)
126
- # data.init("c4d")
127
- # sw = data.data()["software"]
128
- # self.assertEqual(len(sw.supported_host_names()), 1)
129
-
130
- # def test_platforms_method_only_linux(self):
131
- # self.override_default_cache(instance_types=LIN_INSTANCE_TYPES)/
132
- # data.init("c4d")
133
- # data.data()
134
- # self.assertEqual({"linux"}, data.platforms())
135
-
136
- # def test_many_products(self):
137
- # self.override_default_cache(instance_types=LIN_INSTANCE_TYPES)
138
- # data.init("c4d", "maya")
139
- # sw = data.data()["software"]
140
- # self.assertEqual(len(sw.supported_host_names()), 4)
141
-
142
- # def test_product_keyword_translates_to_single_arg(self):
143
- # data.init(product="c4d")
144
- # sw = data.data()["software"]
145
- # self.assertEqual(len(sw.supported_host_names()), 2)
146
-
147
- # def test_product_keyword_all_translates_to_all_products(self):
148
- # data.init(product="all")
149
- # sw = data.data()["software"]
150
- # self.assertEqual(len(sw.supported_host_names()), 11)
151
-
152
- # def test_data_raises_if_both_products_and_kwarg_given(self):
153
- # with self.assertRaises(ValueError):
154
- # data.init("maya", product="c4d")
155
-
156
- # def test_data_raises_if_products_and_kwarg_given(self):
157
- # with self.assertRaises(ValueError):
158
- # data.init("maya", product="c4d")
159
-
160
- class TestDataSmoke(unittest.TestCase):
161
-
162
- def test_smoke(self):
163
- self.assertTrue(True)
43
+ """Clean up after each test method."""
44
+ coredata.clear()
45
+
46
+ def test_init_with_single_product(self):
47
+ """Test initializing with a single product"""
48
+ coredata.init("maya-io")
49
+ self.assertEqual(coredata.products(), ["maya-io"])
50
+ self.assertEqual(coredata.platforms(), set(["windows", "linux"]))
51
+
52
+ def test_init_with_multiple_products(self):
53
+ """Test initializing with multiple products"""
54
+ coredata.init("maya-io", "nuke")
55
+ self.assertEqual(coredata.products(), ["maya-io", "nuke"])
56
+
57
+ def test_init_with_deprecated_product(self):
58
+ """Test initializing with deprecated product kwarg"""
59
+ coredata.init(product="maya-io")
60
+ self.assertEqual(coredata.products(), ["maya-io"])
61
+
62
+ def test_init_with_all_products(self):
63
+ """Test initializing with 'all' products"""
64
+ coredata.init(product="all")
65
+ self.assertEqual(coredata.products(), [])
66
+
67
+ def test_init_conflict_raises_error(self):
68
+ """Test that using both products arg and product kwarg raises error"""
69
+ with self.assertRaises(ValueError):
70
+ coredata.init("maya-io", product="nuke")
71
+
72
+ def test_data_requires_init(self):
73
+ """Test that data() raises error if not initialized"""
74
+ with self.assertRaises(ValueError):
75
+ coredata.data()
76
+
77
+ @patch('ciocore.data.api_client')
78
+ def test_data_fetching(self, mock_client):
79
+ """Test fetching data through the data() function"""
80
+ # Setup mock responses
81
+ mock_client.request_projects.return_value = self.mock_api_responses['projects']
82
+ mock_client.request_instance_types.return_value = self.mock_api_responses['instance_types']
83
+ mock_client.request_software_packages.return_value = self.mock_api_responses['software']
84
+ mock_client.request_extra_environment.return_value = self.mock_api_responses['extra_env']
85
+
86
+ coredata.init("maya-io")
87
+ result = coredata.data()
88
+
89
+ self.assertIn("projects", result)
90
+ self.assertIn("instance_types", result)
91
+ self.assertIn("software", result)
92
+ self.assertIn("extra_environment", result)
93
+
94
+ self.assertEqual(result["projects"], self.mock_api_responses["projects"])
95
+ self.assertIsInstance(result["instance_types"], coredata.HardwareSet)
96
+ self.assertIsInstance(result["software"], coredata.PackageTree)
97
+
98
+ @patch('ciocore.data.api_client')
99
+ def test_force_refresh(self, mock_client):
100
+ """Test forcing data refresh"""
101
+ # Setup mock responses
102
+ mock_client.request_projects.return_value = self.mock_api_responses['projects']
103
+ mock_client.request_instance_types.return_value = self.mock_api_responses['instance_types']
104
+ mock_client.request_software_packages.return_value = self.mock_api_responses['software']
105
+ mock_client.request_extra_environment.return_value = self.mock_api_responses['extra_env']
106
+
107
+ coredata.init("maya-io")
108
+ first_data = coredata.data()
109
+
110
+ # Second call without force should not make new API calls
111
+ mock_client.request_projects.reset_mock()
112
+ second_data = coredata.data()
113
+ mock_client.request_projects.assert_not_called()
114
+
115
+ # Call with force=True should make new API calls
116
+ third_data = coredata.data(force=True)
117
+ mock_client.request_projects.assert_called_once()
118
+
119
+ def test_valid_state(self):
120
+ """Test valid() function behavior"""
121
+ self.assertFalse(coredata.valid()) # Should be invalid before initialization
122
+
123
+ coredata.init("maya-io")
124
+ self.assertFalse(coredata.valid()) # Should be invalid before data is fetched
125
+
126
+ with patch('ciocore.data.api_client') as mock_client:
127
+ # Setup mock responses
128
+ mock_client.request_projects.return_value = self.mock_api_responses['projects']
129
+ mock_client.request_instance_types.return_value = self.mock_api_responses['instance_types']
130
+ mock_client.request_software_packages.return_value = self.mock_api_responses['software']
131
+ mock_client.request_extra_environment.return_value = self.mock_api_responses['extra_env']
132
+
133
+ coredata.data() # Fetch data
134
+ self.assertTrue(coredata.valid()) # Should be valid after data is fetched
135
+
136
+ coredata.clear()
137
+ self.assertFalse(coredata.valid()) # Should be invalid after clear
138
+
139
+ @patch('ciocore.data.api_client')
140
+ def test_platforms_filtering(self, mock_client):
141
+ """Test platform filtering based on instance types and software"""
142
+ # Setup mock responses
143
+ mock_client.request_projects.return_value = self.mock_api_responses['projects']
144
+ mock_client.request_instance_types.return_value = self.mock_api_responses['instance_types']
145
+ mock_client.request_software_packages.return_value = self.mock_api_responses['software']
146
+ mock_client.request_extra_environment.return_value = self.mock_api_responses['extra_env']
147
+
148
+ coredata.init("nuke") # nuke only supports linux
149
+ coredata.data()
150
+
151
+ # Should only have linux instance types since nuke only supports linux
152
+ self.assertEqual(coredata.platforms(), {"linux"})
153
+
154
+ @patch('ciocore.data.api_client')
155
+ def test_instances_filter(self, mock_client):
156
+ """Testing that instance_types is passed correctly to api_client"""
157
+ # Set up mock response
158
+ mock_client.request_instance_types.return_value = self.mock_api_responses['instance_types']
159
+ coredata.init("maya-io")
160
+
161
+ # Test with no filter
162
+ coredata.data()
163
+ mock_client.request_instance_types.assert_called_with(filter_param="")
164
+
165
+ # Test with filter and force=True
166
+ mock_client.request_instance_types.reset_mock()
167
+
168
+ instances_filter = "gpu.gpu_count=gte:1:int"
169
+ coredata.data(force=True, instances_filter=instances_filter)
170
+ mock_client.request_instance_types.assert_called_with(filter_param=instances_filter)
171
+
172
+ if __name__ == '__main__':
173
+ unittest.main()
tests/test_submit.py CHANGED
@@ -5,10 +5,7 @@
5
5
 
6
6
  import unittest
7
7
 
8
- try:
9
- from unittest.mock import MagicMock, patch
10
- except ImportError:
11
- from mock import MagicMock, patch
8
+ from unittest.mock import MagicMock, patch
12
9
 
13
10
 
14
11
  def get_required_args():
tests/test_uploader.py CHANGED
@@ -1,10 +1,7 @@
1
1
  import unittest
2
2
  import sys
3
3
 
4
- try:
5
- from unittest import mock
6
- except ImportError:
7
- import mock
4
+ from unittest import mock
8
5
 
9
6
  PY3 = sys.version_info >= (3, 0)
10
7
  BUILTIN_OPEN = "builtins.open" if PY3 else "__builtin__.open"
ciocore/compat.py DELETED
@@ -1,15 +0,0 @@
1
- import sys
2
- if sys.version_info < (3,):
3
- import codecs
4
- def u(x):
5
- return codecs.unicode_escape_decode(x)[0]
6
-
7
- text_type = unicode
8
- binary_type = str
9
- else:
10
- def u(x):
11
- return str(x)
12
-
13
- text_type = str
14
- binary_type = bytes
15
-
@@ -1,101 +0,0 @@
1
- import logging
2
- from ciocore import loggeria
3
-
4
- logger = logging.getLogger("{}.uploader".format(loggeria.CONDUCTOR_LOGGER_NAME))
5
-
6
- class ThreadQueueJob():
7
- pass
8
-
9
- class UploadThreadQueueJob(ThreadQueueJob):
10
-
11
- def __init__(self, path, file_size, presigned_url, file_md5=None, upload_id=None, part_size=None, total_parts=1, part_index=1, kms_key_name=None):
12
-
13
- super().__init__()
14
-
15
- self.path = path
16
- self.file_size = file_size
17
- self.upload_id = upload_id
18
- self.presigned_url = presigned_url
19
- self.file_md5 = file_md5
20
- self.part_size = part_size
21
- self.part_index = part_index
22
- self.total_parts = total_parts
23
- self.kms_key_name = kms_key_name
24
-
25
- logger.info("Creating %s (%s): %s", str(self.__class__), str(self), str(self.__dict__))
26
-
27
- def is_multipart(self):
28
- return self.total_parts != 1
29
-
30
- def is_vendor_aws(self):
31
- return "amazonaws" in self.presigned_url
32
-
33
- def is_vendor_cw(self):
34
- return "coreweave" in self.presigned_url
35
-
36
- @classmethod
37
- def create_from_response(cls, response):
38
-
39
- new_thread_queue_jobs = []
40
-
41
- for part_type, file_request_list in response.items():
42
-
43
- for file_request in file_request_list:
44
- if part_type == "multiPartURLs":
45
-
46
- for part in file_request["parts"]:
47
- new_tqj = cls( path=file_request['filePath'],
48
- file_size = file_request['filePath'],
49
- presigned_url = file_request['preSignedURL'],
50
- file_md5 = file_request['preSignedURL'],
51
- upload_id = file_request['preSignedURL'],
52
- part_size = file_request['preSignedURL'],
53
- part_index = file_request['preSignedURL'])
54
-
55
-
56
- else:
57
- new_tqj = cls( path=file_request['filePath'],
58
- file_size = file_request['filePath'],
59
- presigned_url = file_request['preSignedURL'])
60
-
61
- new_thread_queue_jobs.append(new_tqj)
62
-
63
-
64
-
65
- class MultiPartThreadQueueJob(ThreadQueueJob):
66
-
67
- def __init__(self, path, md5, total_parts=1, part_index=1):
68
-
69
- super().__init__()
70
-
71
- self.upload_id = None
72
- self.md5 = md5
73
- self.project = None
74
- self.path = path
75
- self.part_index = part_index
76
- self.etag = None
77
- self.total_parts = total_parts
78
-
79
- logger.info("Creating %s (%s): %s", str(self.__class__), str(self), str(self.__dict__))
80
-
81
- def is_multipart(self):
82
- return self.total_parts != 1
83
-
84
- # def __str__(self):
85
- # return
86
-
87
- @staticmethod
88
- def aggregate_parts(parts):
89
- """
90
- Helper function to take all the parts of a multipart upload and put
91
- them into a format that's expected for the HTTP call.
92
- """
93
-
94
- completed_parts_payload = []
95
-
96
- for part in parts:
97
- completed_parts_payload.append({'partNumber': part.part,
98
- 'etag': part.etag}
99
- )
100
-
101
- return completed_parts_payload
@@ -1,57 +0,0 @@
1
-
2
-
3
- EXTRA_ENV = [
4
- {
5
- "account_id": "6649535867387904",
6
- "env": [],
7
- },
8
- {
9
- "account_id": "5767615549800448",
10
- "env": [
11
- {
12
- "merge_policy": "prepend",
13
- "name": "test",
14
- "value": "test"
15
- }
16
- ],
17
- },
18
- {
19
- "account_id": "6649535867387904",
20
- "env": [],
21
- },
22
- {
23
- "account_id": "5669544198668288",
24
- "env": [
25
- {
26
- "merge_policy": "append",
27
- "name": "PATH",
28
- "value": "/path/to/scripts"
29
- },
30
- {
31
- "merge_policy": "exclusive",
32
- "name": "RENDER_LOCATION",
33
- "value": "cloud"
34
- },
35
- {
36
- "merge_policy": "exclusive",
37
- "name": "VARIABLE_USED_IN_SCRIPTS",
38
- "value": "true"
39
- },
40
- {
41
- "merge_policy": "exclusive",
42
- "name": "testvar",
43
- "value": "somevalue"
44
- }
45
- ],
46
- },
47
- {
48
- "account_id": "6649535867387904",
49
- "env": [
50
- {
51
- "merge_policy": "exclusive",
52
- "name": "JMEYER",
53
- "value": "JMEYER_ENV_VALUE"
54
- }
55
- ],
56
- }
57
- ]
tests/project_fixtures.py DELETED
@@ -1,8 +0,0 @@
1
-
2
-
3
- PROJECTS = [
4
- "Deadpool",
5
- "Harry Potter & the chamber of secrets",
6
- "Captain Corelli's Mandolin",
7
- "Gone with the Wind",
8
- ]