Skip to content

Commit

Permalink
apply unsafe ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seebi committed Sep 12, 2024
1 parent ed0275c commit c6b4fbf
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 74 deletions.
3 changes: 1 addition & 2 deletions cmem_plugin_base/dataintegration/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Enti


class TransformPlugin(PluginBase):
"""Base class of all transform operator plugins.
"""
"""Base class of all transform operator plugins."""

def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:
"""Transforms a collection of values.
Expand Down
4 changes: 2 additions & 2 deletions cmem_plugin_base/dataintegration/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def generate_id(name: str) -> str:
return re.sub(r"[^a-zA-Z0-9_-]", "", name)


def setup_cmempy_user_access(context: UserContext | None):
def setup_cmempy_user_access(context: UserContext | None) -> None:
"""Setup environment for accessing CMEM with cmempy."""
if context is None:
raise ValueError("No UserContext given.")
Expand All @@ -28,7 +28,7 @@ def setup_cmempy_user_access(context: UserContext | None):
os.environ["CMEM_BASE_URI"] = os.environ["DEPLOY_BASE_URL"]


def setup_cmempy_super_user_access():
def setup_cmempy_super_user_access() -> None:
"""Setup environment for accessing CMEM with cmempy.
The helper function is used to setup the environment for accessing CMEM with cmempy.
Expand Down
9 changes: 3 additions & 6 deletions cmem_plugin_base/dataintegration/utils/entity_builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""utils module for building entities from python objects dict|list."""


from ulid import ULID

from cmem_plugin_base.dataintegration.entity import Entities, Entity, EntityPath, EntitySchema
Expand Down Expand Up @@ -95,7 +94,7 @@ def _get_schema(data: dict | list):
return path_to_schema_map


def extend_path_list(path_to_entities, sub_path_to_entities):
def extend_path_list(path_to_entities, sub_path_to_entities) -> None:
"""Extend a dictionary of paths to entities by merging with another.
This function takes two dictionaries, `path_to_entities` and `sub_path_to_entities`,
Expand Down Expand Up @@ -163,8 +162,7 @@ def _get_entities(
data: dict | list,
path_to_schema_map: dict[str, EntitySchema],
) -> dict[str, list[Entity]]:
"""Get entities based on the schema, data, and sub-entities.
"""
"""Get entities based on the schema, data, and sub-entities."""
path_to_entities: dict[str, list[Entity]] = {}
if isinstance(data, list):
for _ in data:
Expand All @@ -182,8 +180,7 @@ def _get_entities(


def build_entities_from_data(data: dict | list) -> Entities | None:
"""Get entities from a data object.
"""
"""Get entities from a data object."""
path_to_schema_map = _get_schema(data)
if not path_to_schema_map:
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/parameter_types/test_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
CHOICE_LIST = collections.OrderedDict({"ONE": "First Option", "TWO": "Second Option"})


def test_dataset_parameter_type_completion():
def test_dataset_parameter_type_completion() -> None:
"""Test dataset parameter type completion"""
parameter = ChoiceParameterType(choice_list=CHOICE_LIST)
context = TestPluginContext()
Expand Down
28 changes: 14 additions & 14 deletions tests/parameter_types/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class CodeParameterTest(unittest.TestCase):
"""Code Parameter Test"""

def test__detection(self):
def test__detection(self) -> None:
"""Test detection"""
Plugin.plugins = []

Expand Down Expand Up @@ -57,29 +57,29 @@ def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:
MyTransformPlugin()

plugin = Plugin.plugins[0]
self.assertEqual(plugin.parameters[0].param_type.name, "code-xml")
self.assertEqual(plugin.parameters[1].param_type.name, "code-json")
self.assertEqual(plugin.parameters[2].param_type.name, "code-jinja2")
self.assertEqual(plugin.parameters[3].param_type.name, "code-sql")
self.assertEqual(plugin.parameters[4].param_type.name, "code-yaml")
self.assertEqual(plugin.parameters[5].param_type.name, "code-sparql")
self.assertEqual(plugin.parameters[6].param_type.name, "code-turtle")
self.assertEqual(plugin.parameters[7].param_type.name, "code-python")

def test_serialization(self):
assert plugin.parameters[0].param_type.name == "code-xml"
assert plugin.parameters[1].param_type.name == "code-json"
assert plugin.parameters[2].param_type.name == "code-jinja2"
assert plugin.parameters[3].param_type.name == "code-sql"
assert plugin.parameters[4].param_type.name == "code-yaml"
assert plugin.parameters[5].param_type.name == "code-sparql"
assert plugin.parameters[6].param_type.name == "code-turtle"
assert plugin.parameters[7].param_type.name == "code-python"

def test_serialization(self) -> None:
"""Test serialization from/to strings"""
jinja_type = CodeParameterType[JinjaCode]("jinja2")

# Create a jinja code instance from a string
jinja_code = jinja_type.from_string("my code", TestPluginContext(user=None))
self.assertEqual(jinja_code.code, "my code")
assert jinja_code.code == "my code"

# Convert jinja code instance to a string
code_str = jinja_type.to_string(jinja_code)
self.assertEqual(code_str, "my code")
assert code_str == "my code"

# Make sure __str__ will return the code itself
self.assertEqual(str(jinja_code), "my code")
assert str(jinja_code) == "my code"


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/parameter_types/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@needs_cmem
def test_dataset_parameter_type_completion(json_dataset):
def test_dataset_parameter_type_completion(json_dataset) -> None:
"""Test dataset parameter type completion"""
project_name = json_dataset["project"]
dataset_name = json_dataset["id"]
Expand Down
5 changes: 2 additions & 3 deletions tests/parameter_types/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""graph parameter type tests"""

from cmem_plugin_base.dataintegration.parameter.graph import GraphParameterType

from ..utils import TestPluginContext, needs_cmem
from tests.utils import TestPluginContext, needs_cmem


@needs_cmem
def test_graph_parameter_type_completion():
def test_graph_parameter_type_completion() -> None:
"""Test graph parameter type completion"""
parameter = GraphParameterType(show_system_graphs=True)
context = TestPluginContext()
Expand Down
4 changes: 2 additions & 2 deletions tests/parameter_types/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class PasswordParameterTest(unittest.TestCase):
"""Password Parameter Test"""

def test__detection(self):
def test__detection(self) -> None:
"""Test detection"""
Plugin.plugins = []

Expand All @@ -33,7 +33,7 @@ def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:

plugin = Plugin.plugins[0]
password_param = plugin.parameters[0]
self.assertEqual(password_param.param_type.name, PasswordParameterType.name)
assert password_param.param_type.name == PasswordParameterType.name


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/parameter_types/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@needs_cmem
def test_resource_parameter_type_completion(json_resource):
def test_resource_parameter_type_completion(json_resource) -> None:
"""Test resource parameter type completion"""
project_name = json_resource.project_name
resource_name = json_resource.resource_name
Expand Down
18 changes: 9 additions & 9 deletions tests/test_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class PluginTest(unittest.TestCase):
"""Plugin Test Class"""

def test__basic_parameters(self):
def test__basic_parameters(self) -> None:
"""Test basic parameters"""
Plugin.plugins = []

Expand All @@ -42,20 +42,20 @@ def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:
plugin = Plugin.plugins[0]

no_default_par = plugin.parameters[0]
self.assertEqual(no_default_par.param_type.name, StringParameterType.name)
self.assertIsNone(no_default_par.default_value)
assert no_default_par.param_type.name == StringParameterType.name
assert no_default_par.default_value is None

string_par = plugin.parameters[1]
self.assertEqual(string_par.param_type.name, StringParameterType.name)
self.assertEqual(string_par.default_value, "value")
assert string_par.param_type.name == StringParameterType.name
assert string_par.default_value == "value"

float_par = plugin.parameters[2]
self.assertEqual(float_par.param_type.name, FloatParameterType.name)
self.assertEqual(float_par.default_value, 1.5)
assert float_par.param_type.name == FloatParameterType.name
assert float_par.default_value == 1.5

bool_par = plugin.parameters[3]
self.assertEqual(bool_par.param_type.name, BoolParameterType.name)
self.assertEqual(bool_par.default_value, True)
assert bool_par.param_type.name == BoolParameterType.name
assert bool_par.default_value is True


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@pytest.mark.skip(reason="cmem-plugin-examples is not added")
def test_discover_plugins():
def test_discover_plugins() -> None:
"""Test plugin discovery."""
plugins = discover_plugins("cmem_plugin").plugins

Expand Down
8 changes: 4 additions & 4 deletions tests/test_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> None
return None


def test_for_errors():
def test_for_errors() -> None:
"""Test Icon inits with errors."""
with pytest.raises(FileNotFoundError):
Icon(file_name="no.file", package=__package__)
Expand All @@ -31,20 +31,20 @@ def test_for_errors():
Icon(file_name="icons/test.nomime", package=__package__)


def test_svg():
def test_svg() -> None:
"""Test SVG icon"""
icon = Icon(file_name="icons/test.svg", package=__package__)
assert icon.mime_type == "image/svg+xml"
assert len(str(icon)) == 906


def test_png():
def test_png() -> None:
"""Test PNG icon"""
icon = Icon(file_name="icons/test.png", package=__package__)
assert icon.mime_type == "image/png"
assert len(str(icon)) == 63818


def test_plugin_init():
def test_plugin_init() -> None:
"""Test initialization of a workflow plugin with custom icon."""
_ = MyWorkflowPlugin()
2 changes: 1 addition & 1 deletion tests/test_output_only_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def execute(self, inputs=(), context=()) -> Entities:
return Entities(entities=iter([entity1, entity2]), schema=schema)


def test_output_only_plugin():
def test_output_only_plugin() -> None:
"""Test example Workflow Plugin."""
output_only = OutputOnlyPlugin(param1="test")
result = output_only.execute()
Expand Down
36 changes: 18 additions & 18 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TypesTest(unittest.TestCase):
class MissingType:
"""Test Missing Type"""

def test_missing_type(self):
def test_missing_type(self) -> None:
"""Test missing type"""
self.assertRaisesRegex(
ValueError,
Expand All @@ -32,22 +32,22 @@ def test_missing_type(self):
class BasicTypesTest(unittest.TestCase):
"""Test Basic Types"""

def test_detection(self):
def test_detection(self) -> None:
"""Test detection"""
self.assertEqual(ParameterTypes.get_type(str).name, "string")
self.assertEqual(ParameterTypes.get_type(int).name, "Long")
self.assertEqual(ParameterTypes.get_type(float).name, "double")
self.assertEqual(ParameterTypes.get_type(bool).name, "boolean")
assert ParameterTypes.get_type(str).name == "string"
assert ParameterTypes.get_type(int).name == "Long"
assert ParameterTypes.get_type(float).name == "double"
assert ParameterTypes.get_type(bool).name == "boolean"

def test_conversion(self):
def test_conversion(self) -> None:
"""Test conversion"""
int_type = ParameterTypes.get_type(int)
float_type = ParameterTypes.get_type(float)
bool_type = ParameterTypes.get_type(bool)
self.assertEqual(int_type.from_string(int_type.to_string(3), context), 3)
self.assertEqual(float_type.from_string(int_type.to_string(1.2), context), 1.2)
self.assertEqual(bool_type.from_string(int_type.to_string(True), context), True)
self.assertEqual(bool_type.from_string(int_type.to_string(False), context), False)
assert int_type.from_string(int_type.to_string(3), context) == 3
assert float_type.from_string(int_type.to_string(1.2), context) == 1.2
assert bool_type.from_string(int_type.to_string(True), context) is True
assert bool_type.from_string(int_type.to_string(False), context) is False


class EnumTest(unittest.TestCase):
Expand All @@ -60,17 +60,17 @@ class Color(Enum):
GREEN = 2
BLUE = 3

def test_detection(self):
def test_detection(self) -> None:
"""Test detection"""
self.assertEqual(ParameterTypes.get_type(EnumTest.Color).name, "enumeration")
assert ParameterTypes.get_type(EnumTest.Color).name == "enumeration"

def test_conversion(self):
def test_conversion(self) -> None:
"""Test conversion"""
enum = EnumParameterType(EnumTest.Color)
self.assertEqual(enum.to_string(enum.from_string("RED", context)), "RED")
self.assertEqual(enum.to_string(enum.from_string("GREEN", context)), "GREEN")
assert enum.to_string(enum.from_string("RED", context)) == "RED"
assert enum.to_string(enum.from_string("GREEN", context)) == "GREEN"

def test_invalid_values(self):
def test_invalid_values(self) -> None:
"""Test invalid values"""
enum = EnumParameterType(EnumTest.Color)
self.assertRaisesRegex(
Expand All @@ -82,7 +82,7 @@ def test_invalid_values(self):
ValueError, "not a valid value", lambda: enum.from_string("CYAN", context)
)

def test_autocomplete(self):
def test_autocomplete(self) -> None:
"""Test autocomplete"""
enum = EnumParameterType(EnumTest.Color)
self.assertListEqual(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_utils_build_entities_from_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cmem_plugin_base.dataintegration.utils.entity_builder import build_entities_from_data


def test_single_object():
def test_single_object() -> None:
"""Test generation of entities and schema for a simple JSON object."""
test_data = """
{
Expand All @@ -29,7 +29,7 @@ def test_single_object():
)


def test_single_object_one_level():
def test_single_object_one_level() -> None:
"""Test generation of entities and schema for a JSON object with one level of
hierarchy
"""
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_single_object_one_level():
)


def test_single_object_one_level_array():
def test_single_object_one_level_array() -> None:
"""Test generation of entities and schema for a JSON object with array object in
first level of hierarchy
"""
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_single_object_one_level_array():
)


def test_single_object_two_level_array():
def test_single_object_two_level_array() -> None:
"""Test generation of entities and schema for a JSON object with two levels of
hierarchy
"""
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_single_object_two_level_array():
)


def test_array_object():
def test_array_object() -> None:
"""Test generation of entities and schema for a simple array JSON object."""
test_data = """
[{
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_array_object():
)


def test_empty_object():
def test_empty_object() -> None:
"""Test empty json object input"""
test_data = """[]"""
data = json.loads(test_data)
Expand Down
Loading

0 comments on commit c6b4fbf

Please sign in to comment.