Add trailing commas for the pre-commit hook......

master
Michael Chisholm 2020-02-07 18:58:45 -05:00
parent 19707677c9
commit bf83ca62b3
2 changed files with 200 additions and 198 deletions

View File

@ -86,7 +86,7 @@ def _detect_spec_version(stix_dict):
"v21", "v21",
max( max(
_detect_spec_version(obj) for obj in stix_dict["objects"] _detect_spec_version(obj) for obj in stix_dict["objects"]
) ),
) )
elif obj_type in STIX2_OBJ_MAPS["v21"]["observables"]: elif obj_type in STIX2_OBJ_MAPS["v21"]["observables"]:
# Non-bundle object with an ID and without spec_version. Could be a # Non-bundle object with an ID and without spec_version. Could be a

View File

@ -5,205 +5,207 @@ import pytest
from stix2.core import _detect_spec_version from stix2.core import _detect_spec_version
@pytest.mark.parametrize("obj_dict, expected_ver", [ @pytest.mark.parametrize(
# STIX 2.0 examples "obj_dict, expected_ver", [
( # STIX 2.0 examples
{ (
"type": "identity", {
"id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486", "type": "identity",
"created": "1972-05-21T05:33:09.000Z", "id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486",
"modified": "1973-05-28T02:10:54.000Z", "created": "1972-05-21T05:33:09.000Z",
"name": "alice", "modified": "1973-05-28T02:10:54.000Z",
"identity_class": "individual" "name": "alice",
}, "identity_class": "individual",
"v20" },
), "v20"
( ),
{ (
"type": "relationship", {
"id": "relationship--63b0f1b7-925e-4795-ac9b-61fb9f235f1a", "type": "relationship",
"created": "1981-08-11T13:48:19.000Z", "id": "relationship--63b0f1b7-925e-4795-ac9b-61fb9f235f1a",
"modified": "2000-02-16T15:33:15.000Z", "created": "1981-08-11T13:48:19.000Z",
"source_ref": "attack-pattern--9391504a-ef29-4a41-a257-5634d9edc391", "modified": "2000-02-16T15:33:15.000Z",
"target_ref": "identity--ba18dde2-56d3-4a34-aa0b-fc56f5be568f", "source_ref": "attack-pattern--9391504a-ef29-4a41-a257-5634d9edc391",
"relationship_type": "targets" "target_ref": "identity--ba18dde2-56d3-4a34-aa0b-fc56f5be568f",
}, "relationship_type": "targets",
"v20" },
), "v20"
( ),
{ (
"type": "file", {
"name": "notes.txt" "type": "file",
}, "name": "notes.txt",
"v20" },
), "v20"
( ),
{ (
"type": "marking-definition", {
"id": "marking-definition--2a13090f-a493-4b70-85fe-fa021d91dcd2", "type": "marking-definition",
"created": "1998-03-27T19:44:53.000Z", "id": "marking-definition--2a13090f-a493-4b70-85fe-fa021d91dcd2",
"definition_type": "statement", "created": "1998-03-27T19:44:53.000Z",
"definition": { "definition_type": "statement",
"statement": "Copyright (c) ACME Corp." "definition": {
} "statement": "Copyright (c) ACME Corp.",
},
"v20"
),
(
{
"type": "bundle",
"id": "bundle--8379cb02-8131-47c8-8a7c-9a1f0e0986b1",
"spec_version": "2.0",
"objects": [
{
"type": "identity",
"id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486",
"created": "1972-05-21T05:33:09.000Z",
"modified": "1973-05-28T02:10:54.000Z",
"name": "alice",
"identity_class": "individual"
}, },
{ },
"type": "marking-definition", "v20"
"id": "marking-definition--2a13090f-a493-4b70-85fe-fa021d91dcd2", ),
"created": "1998-03-27T19:44:53.000Z", (
"definition_type": "statement", {
"definition": { "type": "bundle",
"statement": "Copyright (c) ACME Corp." "id": "bundle--8379cb02-8131-47c8-8a7c-9a1f0e0986b1",
} "spec_version": "2.0",
} "objects": [
] {
}, "type": "identity",
"v20" "id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486",
), "created": "1972-05-21T05:33:09.000Z",
# STIX 2.1 examples "modified": "1973-05-28T02:10:54.000Z",
( "name": "alice",
{ "identity_class": "individual",
"type": "identity", },
"id": "identity--22299b4c-bc38-4485-ad7d-8222f01c58c7", {
"spec_version": "2.1", "type": "marking-definition",
"created": "1995-07-24T04:07:48.000Z", "id": "marking-definition--2a13090f-a493-4b70-85fe-fa021d91dcd2",
"modified": "2001-07-01T09:33:17.000Z", "created": "1998-03-27T19:44:53.000Z",
"name": "alice" "definition_type": "statement",
}, "definition": {
"v21" "statement": "Copyright (c) ACME Corp.",
), },
( },
{ ],
"type": "relationship", },
"id": "relationship--0eec232d-e1ea-4f85-8e78-0de6ae9d09f0", "v20"
"spec_version": "2.1", ),
"created": "1975-04-05T10:47:22.000Z", # STIX 2.1 examples
"modified": "1983-04-25T20:56:00.000Z", (
"source_ref": "attack-pattern--9391504a-ef29-4a41-a257-5634d9edc391", {
"target_ref": "identity--ba18dde2-56d3-4a34-aa0b-fc56f5be568f", "type": "identity",
"relationship_type": "targets" "id": "identity--22299b4c-bc38-4485-ad7d-8222f01c58c7",
}, "spec_version": "2.1",
"v21" "created": "1995-07-24T04:07:48.000Z",
), "modified": "2001-07-01T09:33:17.000Z",
( "name": "alice",
{ },
"type": "file", "v21"
"id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe", ),
"spec_version": "2.1", (
"name": "notes.txt" {
}, "type": "relationship",
"v21" "id": "relationship--0eec232d-e1ea-4f85-8e78-0de6ae9d09f0",
), "spec_version": "2.1",
( "created": "1975-04-05T10:47:22.000Z",
{ "modified": "1983-04-25T20:56:00.000Z",
"type": "file", "source_ref": "attack-pattern--9391504a-ef29-4a41-a257-5634d9edc391",
"id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe", "target_ref": "identity--ba18dde2-56d3-4a34-aa0b-fc56f5be568f",
"name": "notes.txt" "relationship_type": "targets",
}, },
"v21" "v21"
), ),
( (
{ {
"type": "marking-definition", "type": "file",
"spec_version": "2.1", "id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe",
"id": "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", "spec_version": "2.1",
"created": "2017-01-20T00:00:00.000Z", "name": "notes.txt",
"definition_type": "tlp", },
"name": "TLP:GREEN", "v21"
"definition": { ),
"tlp": "green" (
} {
}, "type": "file",
"v21" "id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe",
), "name": "notes.txt",
( },
{ "v21"
"type": "bundle", ),
"id": "bundle--d5787acd-1ffd-4630-ada3-6857698f6287", (
"objects": [ {
{ "type": "marking-definition",
"type": "identity", "spec_version": "2.1",
"id": "identity--22299b4c-bc38-4485-ad7d-8222f01c58c7", "id": "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da",
"spec_version": "2.1", "created": "2017-01-20T00:00:00.000Z",
"created": "1995-07-24T04:07:48.000Z", "definition_type": "tlp",
"modified": "2001-07-01T09:33:17.000Z", "name": "TLP:GREEN",
"name": "alice" "definition": {
"tlp": "green",
}, },
{ },
"type": "file", "v21"
"id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe", ),
"name": "notes.txt" (
}, {
] "type": "bundle",
}, "id": "bundle--d5787acd-1ffd-4630-ada3-6857698f6287",
"v21" "objects": [
), {
# Mixed spec examples "type": "identity",
( "id": "identity--22299b4c-bc38-4485-ad7d-8222f01c58c7",
{ "spec_version": "2.1",
"type": "bundle", "created": "1995-07-24T04:07:48.000Z",
"id": "bundle--e1a01e29-3432-401a-ab9f-c1082b056605", "modified": "2001-07-01T09:33:17.000Z",
"objects": [ "name": "alice",
{ },
"type": "identity", {
"id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486", "type": "file",
"created": "1972-05-21T05:33:09.000Z", "id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe",
"modified": "1973-05-28T02:10:54.000Z", "name": "notes.txt",
"name": "alice", },
"identity_class": "individual" ],
}, },
{ "v21"
"type": "relationship", ),
"id": "relationship--63b0f1b7-925e-4795-ac9b-61fb9f235f1a", # Mixed spec examples
"created": "1981-08-11T13:48:19.000Z", (
"modified": "2000-02-16T15:33:15.000Z", {
"source_ref": "attack-pattern--9391504a-ef29-4a41-a257-5634d9edc391", "type": "bundle",
"target_ref": "identity--ba18dde2-56d3-4a34-aa0b-fc56f5be568f", "id": "bundle--e1a01e29-3432-401a-ab9f-c1082b056605",
"relationship_type": "targets" "objects": [
}, {
] "type": "identity",
}, "id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486",
"v21" "created": "1972-05-21T05:33:09.000Z",
), "modified": "1973-05-28T02:10:54.000Z",
( "name": "alice",
{ "identity_class": "individual",
"type": "bundle", },
"id": "bundle--eecad3d9-bb9a-4263-93f6-1c0ccc984574", {
"objects": [ "type": "relationship",
{ "id": "relationship--63b0f1b7-925e-4795-ac9b-61fb9f235f1a",
"type": "identity", "created": "1981-08-11T13:48:19.000Z",
"id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486", "modified": "2000-02-16T15:33:15.000Z",
"created": "1972-05-21T05:33:09.000Z", "source_ref": "attack-pattern--9391504a-ef29-4a41-a257-5634d9edc391",
"modified": "1973-05-28T02:10:54.000Z", "target_ref": "identity--ba18dde2-56d3-4a34-aa0b-fc56f5be568f",
"name": "alice", "relationship_type": "targets",
"identity_class": "individual" },
}, ],
{ },
"type": "file", "v21"
"id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe", ),
"name": "notes.txt" (
}, {
] "type": "bundle",
}, "id": "bundle--eecad3d9-bb9a-4263-93f6-1c0ccc984574",
"v21" "objects": [
) {
]) "type": "identity",
"id": "identity--d7f72e8d-657a-43ec-9324-b3ec67a97486",
"created": "1972-05-21T05:33:09.000Z",
"modified": "1973-05-28T02:10:54.000Z",
"name": "alice",
"identity_class": "individual",
},
{
"type": "file",
"id": "file--5eef3404-6a94-4db3-9a1a-5684cbea0dfe",
"name": "notes.txt",
},
],
},
"v21"
),
],
)
def test_spec_version_detect(obj_dict, expected_ver): def test_spec_version_detect(obj_dict, expected_ver):
detected_ver = _detect_spec_version(obj_dict) detected_ver = _detect_spec_version(obj_dict)