Skip to content
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
11 changes: 10 additions & 1 deletion tests/test_emailobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@
from typing import TypeVar
from zipfile import ZipFile

from pymisp.tools import EMailObject
from pymisp.exceptions import InvalidMISPObject

# EMailObject is only exported when the email extra is installed. Importing it
# unguarded makes this module a collection error rather than a skip, which
# fails the whole run for anyone who installed pymisp without extras.
try:
from pymisp.tools import EMailObject
HAS_EMAIL_EXTRA = True
except ImportError:
HAS_EMAIL_EXTRA = False

T = TypeVar('T', bound='TestEmailObject')


@unittest.skipUnless(HAS_EMAIL_EXTRA, "requires the email extra")
class TestEmailObject(unittest.TestCase):

eml_1: BytesIO
Expand Down
2 changes: 2 additions & 0 deletions tests/test_fileobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import unittest
import json
from pymisp.tools import FileObject
from pymisp.tools.fileobject import HAS_MAGIC
import pathlib


class TestFileObject(unittest.TestCase):
@unittest.skipUnless(HAS_MAGIC, "requires the fileobjects extra (libmagic)")
def test_mimeType(self) -> None:
file_object = FileObject(filepath=pathlib.Path(__file__))
attributes = json.loads(file_object.to_json())['Attribute']
Expand Down
5 changes: 5 additions & 0 deletions tests/test_openioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
pass



# Two children of an AND-indicator whose combined search-context pair is NOT a
# defined composite (RegistryItem/Value + FileItem/Md5sum). These must come back
# as their two individual attributes, not a merged composite.
Expand Down Expand Up @@ -54,6 +55,10 @@
</ioc>"""


# Every test here calls load_openioc, which raises when bs4 is absent. The
# import guard above already anticipates bs4 being missing; without this the
# tests fail instead of skipping.
@unittest.skipUnless(openioc.has_bs4, "requires the openioc extra (bs4)")
class TestOpenIOC(unittest.TestCase):

def test_non_composite_and_indicator_not_merged(self) -> None:
Expand Down