More repr tests.

stix2.1
Greg Back 2017-02-10 16:09:37 -06:00
parent bc66db94aa
commit dbe98c664a
2 changed files with 5 additions and 1 deletions

View File

@ -104,6 +104,6 @@ class _STIXBase(collections.Mapping):
separators=(",", ": ")) # Don't include spaces after commas.
def __repr__(self):
props = [(k, self[k]) for k in sorted(self._properties)]
props = [(k, self[k]) for k in sorted(self._properties) if self.get(k)]
return "{0}({1})".format(self.__class__.__name__,
", ".join(["{0!s}={1!r}".format(k, v) for k, v in props]))

View File

@ -34,6 +34,7 @@ def test_external_reference_capec():
)
assert str(ref) == CAPEC
assert repr(ref) == "ExternalReference(external_id='CAPEC-550', source_name='capec')"
CAPEC_URL = """{
@ -100,6 +101,9 @@ def test_external_reference_offline():
)
assert str(ref) == OFFLINE
assert repr(ref) == "ExternalReference(description='Threat report', source_name='ACME Threat Intel')"
# Yikes! This works
assert eval("stix2." + repr(ref)) == ref
def test_external_reference_source_required():