Skip to content

Commit 96a1116

Browse files
Ruff check --fix
1 parent 4341ce9 commit 96a1116

File tree

11 files changed

+2390
-2169
lines changed

11 files changed

+2390
-2169
lines changed

src/keboola/component/base.py

Lines changed: 104 additions & 89 deletions
Large diffs are not rendered by default.

src/keboola/component/dao.py

Lines changed: 536 additions & 490 deletions
Large diffs are not rendered by default.

src/keboola/component/interface.py

Lines changed: 447 additions & 427 deletions
Large diffs are not rendered by default.

src/keboola/component/sync_actions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from abc import ABC
99
from dataclasses import dataclass
1010
from enum import Enum
11-
from typing import Union, List, Optional
11+
from typing import List, Optional, Union
1212

1313

1414
@dataclass
@@ -23,15 +23,14 @@ def __post_init__(self):
2323
In other cases exception is thrown and printed via stderr.
2424
2525
"""
26-
self.status = 'success'
26+
self.status = "success"
2727

2828
def __str__(self):
2929
# the None values / attributes will be ignored.
30-
dict_obj = dataclasses.asdict(self, dict_factory=lambda x: {k: v for (k, v) in x if
31-
v is not None})
30+
dict_obj = dataclasses.asdict(self, dict_factory=lambda x: {k: v for (k, v) in x if v is not None})
3231
# hack to add default status
3332
if self.status:
34-
dict_obj['status'] = self.status
33+
dict_obj["status"] = self.status
3534
return json.dumps(dict_obj)
3635

3736

@@ -56,6 +55,7 @@ class SelectElement(SyncActionResult):
5655
"""
5756
For select elements. Label is optional and value will be used
5857
"""
58+
5959
value: str
6060
label: Optional[str] = None
6161

@@ -77,13 +77,14 @@ def process_sync_action_result(result: Union[None, List[dict], dict, SyncActionR
7777
if isinstance(result, SyncActionResult):
7878
result_str = str(result)
7979
elif isinstance(result, list):
80-
result_str = f'[{", ".join([json.dumps(r) if isinstance(r, dict) else str(r) for r in result])}]'
80+
result_str = f"[{', '.join([json.dumps(r) if isinstance(r, dict) else str(r) for r in result])}]"
8181
elif result is None:
82-
result_str = json.dumps({'status': 'success'})
82+
result_str = json.dumps({"status": "success"})
8383
elif isinstance(result, dict):
8484
# for backward compatibility
8585
result_str = json.dumps(result)
8686
else:
87-
raise ValueError("Result of sync action must be either None or an instance of SyncActionResult "
88-
"or a List[SyncActionResult]")
87+
raise ValueError(
88+
"Result of sync action must be either None or an instance of SyncActionResult or a List[SyncActionResult]"
89+
)
8990
return result_str

src/keboola/component/table_schema.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from typing import List, Dict
2-
from typing import Optional, Union
3-
from keboola.component.dao import SupportedDataTypes
41
from dataclasses import dataclass
2+
from typing import Dict, List, Optional, Union
3+
4+
from keboola.component.dao import SupportedDataTypes
55

66

77
@dataclass
88
class FieldSchema:
99
"""
1010
Defines the name and type specifications of a single field in a table
1111
"""
12+
1213
name: str
1314
base_type: Optional[Union[SupportedDataTypes, str]] = None
1415
description: Optional[str] = None
@@ -22,6 +23,7 @@ class TableSchema:
2223
"""
2324
TableSchema class is used to define the schema and metadata of a table.
2425
"""
26+
2527
name: str
2628
fields: List[FieldSchema]
2729
primary_keys: Optional[List[str]] = None
@@ -79,10 +81,12 @@ def init_table_schema_from_dict(json_table_schema: Dict) -> TableSchema:
7981
json_table_schema["fields"] = [FieldSchema(**field) for field in json_table_schema["fields"]]
8082
except TypeError as type_error:
8183
raise KeyError(
82-
f"When creating the table schema the definition of columns failed : {type_error}") from type_error
84+
f"When creating the table schema the definition of columns failed : {type_error}"
85+
) from type_error
8386
try:
8487
ts = TableSchema(**json_table_schema)
8588
except TypeError as type_error:
8689
raise KeyError(
87-
f"When creating the table schema the definition of the table failed : {type_error}") from type_error
90+
f"When creating the table schema the definition of the table failed : {type_error}"
91+
) from type_error
8892
return ts

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
import sys
33

44
# just in case include in path
5-
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1].joinpath('src')))
5+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1].joinpath("src")))

tests/test_base.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class MockComponent(ComponentBase):
1212
def run(self):
13-
return 'run_executed'
13+
return "run_executed"
1414

1515

1616
class MockComponentFail(ComponentBase):
@@ -19,44 +19,40 @@ def run(self):
1919

2020

2121
class TestCommonInterface(unittest.TestCase):
22-
2322
def setUp(self):
24-
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
25-
'data_examples', 'data1')
23+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data_examples", "data1")
2624
os.environ["KBC_DATADIR"] = path
2725

2826
def test_default_arguments_pass(self):
2927
MockComponent()
3028

3129
def test_missing_config_parameters_fail(self):
3230
with self.assertRaises(UserException):
33-
MockComponent(required_parameters=['missing'])
31+
MockComponent(required_parameters=["missing"])
3432

3533
def test_missing_image_parameters_fail(self):
3634
with self.assertRaises(UserException):
37-
c = MockComponent(required_image_parameters=['missing'])
35+
c = MockComponent(required_image_parameters=["missing"])
3836
c.execute_action()
3937

4038
def test_missing_action_fail(self):
41-
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
42-
'data_examples', 'data_custom_action')
39+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data_examples", "data_custom_action")
4340
os.environ["KBC_DATADIR"] = path
4441
with self.assertRaises(AttributeError):
4542
MockComponent().execute_action()
4643

4744
def test_run_action_passes(self):
48-
self.assertEqual(MockComponent().execute_action(), 'run_executed')
45+
self.assertEqual(MockComponent().execute_action(), "run_executed")
4946

5047
def test_custom_action_passes(self):
51-
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
52-
'data_examples', 'data_custom_action')
48+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data_examples", "data_custom_action")
5349
os.environ["KBC_DATADIR"] = path
5450

5551
class CustomActionComponent(ComponentBase):
5652
def run(self):
5753
pass
5854

59-
@sync_action('custom_action')
55+
@sync_action("custom_action")
6056
def test_action(self):
6157
return [SelectElement("test")]
6258

@@ -68,40 +64,37 @@ def test_run_action_fails_with_user_error(self):
6864

6965
def test_system_action_name_fail(self):
7066
with self.assertRaises(ValueError):
67+
7168
class ComponentInvalidActionName(ComponentBase):
7269
def run(self):
7370
pass
7471

75-
@sync_action('run')
72+
@sync_action("run")
7673
def test_action(self):
7774
pass
7875

79-
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
80-
'data_examples', 'data_custom_action')
76+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data_examples", "data_custom_action")
8177
os.environ["KBC_DATADIR"] = path
8278

8379
ComponentInvalidActionName().execute_action()
8480

85-
@patch('sys.stdout', new_callable=StringIO)
81+
@patch("sys.stdout", new_callable=StringIO)
8682
def test_sync_action_prints_valid_message(self, stdout):
87-
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
88-
'data_examples', 'data_custom_action')
83+
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data_examples", "data_custom_action")
8984
os.environ["KBC_DATADIR"] = path
9085

9186
class CustomActionComponent(ComponentBase):
9287
def run(self):
9388
pass
9489

95-
@sync_action('custom_action')
90+
@sync_action("custom_action")
9691
def get_columns(self):
97-
return [SelectElement("value_a", "label_a"),
98-
SelectElement("value_b")
99-
]
92+
return [SelectElement("value_a", "label_a"), SelectElement("value_b")]
10093

10194
CustomActionComponent().execute_action()
10295
expected = '[{"value": "value_a", "label": "label_a"}, {"value": "value_b", "label": "value_b"}]'
10396
self.assertEqual(stdout.getvalue(), expected)
10497

10598

106-
if __name__ == '__main__':
99+
if __name__ == "__main__":
107100
unittest.main()

0 commit comments

Comments
 (0)