Skip to content

Commit daae0d7

Browse files
authored
Merge pull request #55 from mj0nez/pluginmnt-segmentfactory
Fix for PluginMount and SegmentFactory
2 parents bf075e6 + 451079d commit daae0d7

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

pydifact/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(cls, name, bases, attrs):
1111
if not hasattr(cls, "plugins"):
1212
cls.plugins = []
1313
else:
14-
if not hasattr(cls, "__omitted__"):
14+
if not getattr(cls, "__omitted__", False):
1515
cls.plugins.append(cls)
1616

1717

pydifact/segments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ def create_segment(
141141
)
142142

143143
for Plugin in SegmentProvider.plugins:
144-
if Plugin().tag == name:
144+
if getattr(Plugin, "tag", "") == name:
145145
s = Plugin(name, *elements)
146+
break
146147
else:
147148
# we don't support this kind of EDIFACT segment (yet), so
148149
# just create a generic Segment()
@@ -155,4 +156,4 @@ def create_segment(
155156
)
156157

157158
# FIXME: characters is not used!
158-
return Segment(name, *elements)
159+
return s

tests/test_segment.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
import pytest
1717

18-
from pydifact.segments import Segment
18+
from pydifact.segments import Segment, SegmentProvider
1919

2020

2121
elements = ["field1", ["field2", "extra"], "stuff"]
@@ -45,3 +45,16 @@ def test_get_non_existing_element():
4545
segment = Segment("OMD", *elements)
4646
with pytest.raises(IndexError):
4747
segment.elements[7]
48+
49+
50+
def test_has_plugin():
51+
class TestSegment(Segment):
52+
53+
tag = "TES"
54+
55+
__omitted__ = False
56+
57+
def validate(self) -> bool:
58+
pass
59+
60+
assert TestSegment in SegmentProvider.plugins

0 commit comments

Comments
 (0)