Skip to content

Commit cd9aceb

Browse files
committed
Improve coverage; remove unused imports
1 parent 3da4fa2 commit cd9aceb

File tree

9 files changed

+21
-31
lines changed

9 files changed

+21
-31
lines changed

.coveragerc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ branch = True
33

44
[report]
55
exclude_lines =
6-
pragma: no cover
7-
6+
NOCOVER
87
raise NotImplementedError
98
assert
109
if __name__ == .__main__.:

contextshell/Action.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from abc import ABC, abstractmethod
22
from contextshell.NodePath import NodePath
33
from contextshell.TreeRoot import ActionArgsPack
4-
from typing import Dict, Union, Any
54

65

76
class Action(ABC):

contextshell/CallableAction.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from collections import OrderedDict
2-
from typing import Callable, Dict, Union, Any, Tuple, List
1+
from typing import Callable
32
from contextshell.TreeRoot import unpack_argument_tree, ActionArgsPack
43
from contextshell.Action import Action
54
from contextshell.NodePath import NodePath
@@ -16,9 +15,9 @@ def invoke(self, target: NodePath, action: NodePath, arguments: ActionArgsPack):
1615
return self.implementation(target, *args, **kwargs)
1716

1817

19-
def action_from_function(method_to_wrap: Callable) -> Action:
20-
action_name: str = method_to_wrap.__name__
18+
def action_from_function(function_to_wrap: Callable) -> Action:
19+
action_name: str = function_to_wrap.__name__
2120
if action_name.endswith('_action'):
2221
action_name = action_name[:-len('_action')]
23-
action_name = action_name.replace('_', '.')
24-
return CallableAction(method_to_wrap, NodePath(action_name))
22+
action_path = NodePath.from_python_name(action_name)
23+
return CallableAction(function_to_wrap, action_path)

contextshell/CommandInterpreter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from contextshell.Command import Command
22
from contextshell.NodePath import NodePath
33
from contextshell.TreeRoot import TreeRoot, parse_argument_tree
4-
from typing import Dict, Union, Any
54

65

76
class CommandInterpreter:

contextshell/NodeTreeRoot.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from contextshell.TreeRoot import TreeRoot, ActionArgsPack
44
from contextshell.Action import Action
55
from contextshell.CallableAction import action_from_function
6-
from typing import Callable, List, Optional, Dict, Union, Any
6+
from typing import List, Optional
77

88

99
# CHECK: how to implement TemporaryTreeRoot (based on NodeTreeRoot)
@@ -13,35 +13,35 @@ def __init__(self):
1313
self.root = self.create_node(None)
1414
self.install_default_actions()
1515

16-
def create_action(self, target: NodePath, path: str, value=None):
16+
def create_action(self, target: NodePath, path: str, value=None): # NOCOVER
1717
self.create(NodePath.join(target, path), value)
1818

19-
def exists_action(self, target: NodePath, path: str) -> bool:
19+
def exists_action(self, target: NodePath, path: str) -> bool: # NOCOVER
2020
return self.exists(NodePath.join(target, path))
2121

22-
def get_action(self, target: NodePath):
22+
def get_action(self, target: NodePath): # NOCOVER
2323
return self.get(target)
2424

25-
def set_action(self, target: NodePath, new_value):
25+
def set_action(self, target: NodePath, new_value): # NOCOVER
2626
return self.set(target, new_value)
2727

28-
def list_action(self, target: NodePath):
28+
def list_action(self, target: NodePath): # NOCOVER
2929
all_list = self.list(target)
3030
return list(filter(lambda p: not self.is_attribute(p), all_list))
3131

32-
def list_all_action(self, target: NodePath):
32+
def list_all_action(self, target: NodePath): # NOCOVER
3333
return self.list(target)
3434

35-
def list_attributes_action(self, target: NodePath):
35+
def list_attributes_action(self, target: NodePath): # NOCOVER
3636
all_list = self.list(target)
3737
return list(filter(self.is_attribute, all_list))
3838

39-
def list_actions_action(self, target: NodePath):
39+
def list_actions_action(self, target: NodePath): # NOCOVER
4040
# FIXME: use the same mechanism as in self.find_action
4141
actions_branch = NodePath.join(target, '@actions')
4242
return self.list(actions_branch)
4343

44-
def remove_action(self, target: NodePath):
44+
def remove_action(self, target: NodePath): # NOCOVER
4545
# CHECK: use 'path' argument?
4646
return self.remove(target)
4747

@@ -89,7 +89,7 @@ def _is_action_implementation(self, node_value) -> bool:
8989
# def install_type(self, type: NodeType):
9090
# raise NotImplementedError()
9191

92-
def is_attribute(self, path: str): # FIXME: is used?
92+
def is_attribute(self, path: str): # CHECK: is used?
9393
return path.startswith('@')
9494

9595
def list_actions(self, path: NodePath) -> List[NodePath]:

tests/functional/CrudTests.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from contextshell.NodeTreeRoot import NodeTreeRoot
2-
from contextshell.NodePath import NodePath
31
from tests.functional.ShellTestsBase import NodeTreeTestsBase
42
from tests.functional.TestExecutor import script_test
5-
import unittest
63

74

85
class CrudTestsBase(NodeTreeTestsBase):

tests/unit/Fakes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from contextshell.NodePath import NodePath
22
from contextshell.Action import Action
3-
from typing import Dict, Callable, Union, Any
4-
from contextshell.TreeRoot import TreeRoot, ActionArgsPack
3+
from typing import Dict
4+
from contextshell.TreeRoot import ActionArgsPack
55

66

77
class FakeTree:

tests/unit/NodePathTests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def test_basename_from_empty(self):
190190

191191
class IsParentOfTests(unittest.TestCase):
192192
def test_is_parent_of(self):
193-
foo = NodePath.cast('.foo')
194-
foobar = NodePath.cast('.foo.bar')
193+
foo = create_path('.foo')
194+
foobar = create_path('.foo.bar')
195195
self.assertTrue(foo.is_parent_of(foobar))
196196
self.assertFalse(foobar.is_parent_of(foo))
197197

tests/unit/NodeTreeRootTests.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import unittest
2-
from typing import Dict, Union, Any
32
from tests.unit.Fakes import FakeAction
43
from contextshell.NodePath import NodePath as np
5-
from contextshell.NodePath import NodePath
6-
from contextshell.TreeRoot import TreeRoot
74

85

96
def create_tree(*args, **kwargs):

0 commit comments

Comments
 (0)