Fix import order, add flake8-import-order plugin

to Tox
stix2.1
clenk 2017-04-24 18:29:56 -04:00
parent fe4c4d78fc
commit cd815bfe84
24 changed files with 70 additions and 44 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
from setuptools import setup, find_packages from setuptools import find_packages, setup
install_requires = [ install_requires = [
'pytz', 'pytz',

View File

@ -1,7 +1,7 @@
"""STIX 2 Bundle object""" """STIX 2 Bundle object"""
from .base import _STIXBase from .base import _STIXBase
from .properties import IDProperty, TypeProperty, Property from .properties import IDProperty, Property, TypeProperty
class Bundle(_STIXBase): class Bundle(_STIXBase):

View File

@ -1,8 +1,8 @@
"""STIX 2 Common Data Types and Properties""" """STIX 2 Common Data Types and Properties"""
from .properties import (ListProperty, BooleanProperty,
ReferenceProperty, TimestampProperty)
from .other import ExternalReference, GranularMarking from .other import ExternalReference, GranularMarking
from .properties import (BooleanProperty, ListProperty, ReferenceProperty,
TimestampProperty)
from .utils import NOW from .utils import NOW
COMMON_PROPERTIES = { COMMON_PROPERTIES = {

View File

@ -1,10 +1,10 @@
"""STIX 2.0 Objects that are neither SDOs nor SROs""" """STIX 2.0 Objects that are neither SDOs nor SROs"""
from .base import _STIXBase from .base import _STIXBase
from .properties import (IDProperty, TypeProperty, ListProperty, TimestampProperty, from .properties import (IDProperty, ListProperty, Property, ReferenceProperty,
ReferenceProperty, Property, SelectorProperty, SelectorProperty, StringProperty, TimestampProperty,
StringProperty) TypeProperty)
from .utils import NOW, get_dict from .utils import get_dict, NOW
class ExternalReference(_STIXBase): class ExternalReference(_STIXBase):

View File

@ -1,11 +1,13 @@
import collections
import datetime as dt
import inspect
import re import re
import uuid import uuid
from six import text_type
import datetime as dt
import pytz
from dateutil import parser from dateutil import parser
import inspect import pytz
import collections from six import text_type
from .base import _STIXBase from .base import _STIXBase

View File

@ -3,9 +3,9 @@
from .base import _STIXBase from .base import _STIXBase
from .common import COMMON_PROPERTIES from .common import COMMON_PROPERTIES
from .other import KillChainPhase from .other import KillChainPhase
from .properties import (Property, ListProperty, StringProperty, TypeProperty, from .properties import (IDProperty, IntegerProperty, ListProperty, Property,
IDProperty, TimestampProperty, ReferenceProperty, ReferenceProperty, StringProperty, TimestampProperty,
IntegerProperty) TypeProperty)
from .utils import NOW from .utils import NOW

View File

@ -2,9 +2,9 @@
from .base import _STIXBase from .base import _STIXBase
from .common import COMMON_PROPERTIES from .common import COMMON_PROPERTIES
from .properties import (ListProperty, StringProperty, TypeProperty, from .properties import (IDProperty, IntegerProperty, ListProperty,
IDProperty, TimestampProperty, ReferenceProperty, ReferenceProperty, StringProperty, TimestampProperty,
IntegerProperty) TypeProperty)
class Relationship(_STIXBase): class Relationship(_STIXBase):

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import ATTACK_PATTERN_ID from .constants import ATTACK_PATTERN_ID

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import CAMPAIGN_ID from .constants import CAMPAIGN_ID

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import COURSE_OF_ACTION_ID from .constants import COURSE_OF_ACTION_ID

View File

@ -1,8 +1,8 @@
"""Tests for stix.ExternalReference""" """Tests for stix.ExternalReference"""
import pytest
import re import re
import pytest
import stix2 import stix2
VERIS = """{ VERIS = """{

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import IDENTITY_ID from .constants import IDENTITY_ID

View File

@ -1,9 +1,8 @@
import datetime as dt import datetime as dt
import re
import pytest import pytest
import pytz import pytz
import re
import stix2 import stix2
from .constants import FAKE_TIME, INDICATOR_ID, INDICATOR_KWARGS from .constants import FAKE_TIME, INDICATOR_ID, INDICATOR_KWARGS

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import INTRUSION_SET_ID from .constants import INTRUSION_SET_ID

View File

@ -1,9 +1,8 @@
import datetime as dt import datetime as dt
import re
import pytest import pytest
import pytz import pytz
import re
import stix2 import stix2
from .constants import FAKE_TIME, MALWARE_ID, MALWARE_KWARGS from .constants import FAKE_TIME, MALWARE_ID, MALWARE_KWARGS
@ -148,3 +147,16 @@ def test_parse_malware_kill_chain_phases():
assert mal.kill_chain_phases[0].phase_name == "reconnaissance" assert mal.kill_chain_phases[0].phase_name == "reconnaissance"
assert mal['kill_chain_phases'][0]['kill_chain_name'] == "lockheed-martin-cyber-kill-chain" assert mal['kill_chain_phases'][0]['kill_chain_name'] == "lockheed-martin-cyber-kill-chain"
assert mal['kill_chain_phases'][0]['phase_name'] == "reconnaissance" assert mal['kill_chain_phases'][0]['phase_name'] == "reconnaissance"
def test_parse_malware_clean_kill_chain_phases():
kill_chain = """
"kill_chain_phases": [
{
"kill_chain_name": "lockheed-martin-cyber-kill-chain",
"phase_name": 1
}
]"""
data = EXPECTED_MALWARE.replace('malware"', 'malware",%s' % kill_chain)
mal = stix2.parse(data)
assert mal['kill_chain_phases'][0]['phase_name'] == "1"

View File

@ -1,8 +1,9 @@
import stix2 import datetime as dt
from stix2.other import TLP_WHITE
import pytest import pytest
import pytz import pytz
import datetime as dt import stix2
from stix2.other import TLP_WHITE
from .constants import MARKING_DEFINITION_ID from .constants import MARKING_DEFINITION_ID

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import OBSERVED_DATA_ID from .constants import OBSERVED_DATA_ID

View File

@ -1,9 +1,8 @@
import pytest import pytest
from stix2.properties import (Property, BooleanProperty, ListProperty, from stix2.properties import (BooleanProperty, IDProperty, IntegerProperty,
StringProperty, TypeProperty, IDProperty, ListProperty, Property, ReferenceProperty,
IntegerProperty, ReferenceProperty, StringProperty, TimestampProperty, TypeProperty)
TimestampProperty)
from .constants import FAKE_TIME from .constants import FAKE_TIME

View File

@ -1,7 +1,9 @@
import stix2 import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt import stix2
from .constants import INDICATOR_KWARGS, REPORT_ID from .constants import INDICATOR_KWARGS, REPORT_ID
EXPECTED = """{ EXPECTED = """{

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import THREAT_ACTOR_ID from .constants import THREAT_ACTOR_ID

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import TOOL_ID from .constants import TOOL_ID

View File

@ -1,6 +1,7 @@
import datetime as dt
import pytest import pytest
import pytz import pytz
import datetime as dt
import stix2 import stix2
from .constants import VULNERABILITY_ID from .constants import VULNERABILITY_ID

View File

@ -1,9 +1,10 @@
"""Utility functions and classes for the stix2 library.""" """Utility functions and classes for the stix2 library."""
import datetime as dt import datetime as dt
import pytz
import json import json
import pytz
# Sentinel value for fields that should be set to the current time. # Sentinel value for fields that should be set to the current time.
# We can't use the standard 'default' approach, since if there are multiple # We can't use the standard 'default' approach, since if there are multiple
# timestamps in a single object, the timestamps will vary by a few microseconds. # timestamps in a single object, the timestamps will vary by a few microseconds.

View File

@ -8,10 +8,11 @@ commands = pytest
[testenv:pycodestyle] [testenv:pycodestyle]
deps = deps =
flake8 flake8
flake8-import-order
pycodestyle pycodestyle
commands = commands =
pycodestyle ./stix2 pycodestyle ./stix2
flake8 --max-line-length=160 flake8 --max-line-length=160 --import-order-style='google'
[pycodestyle] [pycodestyle]
ignore= ignore=