Skip to content

Commit

Permalink
Merge pull request #55 from mj0nez/pluginmnt-segmentfactory
Browse files Browse the repository at this point in the history
Fix for PluginMount and SegmentFactory
  • Loading branch information
nerdoc authored Apr 22, 2023
2 parents bf075e6 + 451079d commit daae0d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pydifact/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(cls, name, bases, attrs):
if not hasattr(cls, "plugins"):
cls.plugins = []
else:
if not hasattr(cls, "__omitted__"):
if not getattr(cls, "__omitted__", False):
cls.plugins.append(cls)


Expand Down
5 changes: 3 additions & 2 deletions pydifact/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ def create_segment(
)

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

# FIXME: characters is not used!
return Segment(name, *elements)
return s
15 changes: 14 additions & 1 deletion tests/test_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest

from pydifact.segments import Segment
from pydifact.segments import Segment, SegmentProvider


elements = ["field1", ["field2", "extra"], "stuff"]
Expand Down Expand Up @@ -45,3 +45,16 @@ def test_get_non_existing_element():
segment = Segment("OMD", *elements)
with pytest.raises(IndexError):
segment.elements[7]


def test_has_plugin():
class TestSegment(Segment):

tag = "TES"

__omitted__ = False

def validate(self) -> bool:
pass

assert TestSegment in SegmentProvider.plugins

0 comments on commit daae0d7

Please sign in to comment.