Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for PluginMount and SegmentFactory #55

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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