From 371d4860dfe0bdd70a16281978089bc3434d99ea Mon Sep 17 00:00:00 2001 From: Greg Back Date: Thu, 28 May 2015 15:45:11 -0500 Subject: [PATCH 1/3] Cache packages for Travis builds. --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8b2423d8..46aa3947 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,16 @@ env: - TOXENV=rhel6 install: + # Cache Wheels for faster tests + - pip install -U pip wheel + - pip isntall -r requirements.txt + - pip install tox +cache: + directories: + - $HOME/.cache/pip + script: - tox From 6489f60c0510ac83f63022fd82f3eae357213971 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Thu, 28 May 2015 16:59:48 -0500 Subject: [PATCH 2/3] Grr typo. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 46aa3947..8ca85d00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ env: install: # Cache Wheels for faster tests - pip install -U pip wheel - - pip isntall -r requirements.txt + - pip install -r requirements.txt - pip install tox From 267b7bbdd2273ba9e36f7327ed4861b57f400687 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Fri, 29 May 2015 09:18:27 -0500 Subject: [PATCH 3/3] Use logging in tests rather than print() --- cybox/test/__init__.py | 17 +++++++++-------- cybox/test/common/hash_test.py | 7 +++++-- cybox/test/common/structured_test_text.py | 4 ++-- cybox/test/core/action_reference_test.py | 7 +++++-- cybox/test/core/object_test.py | 8 +++++--- cybox/test/core/observable_test.py | 5 ++++- cybox/test/objects/email_message_test.py | 7 +++++-- 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/cybox/test/__init__.py b/cybox/test/__init__.py index a97f0092..641221c9 100644 --- a/cybox/test/__init__.py +++ b/cybox/test/__init__.py @@ -2,16 +2,17 @@ # See LICENSE.txt for complete terms. import json +import logging import unittest from mixbox.binding_utils import ExternalEncoding from mixbox.vendor import six from cybox import Entity, EntityList, TypedField -import cybox.bindings.cybox_core as core_binding -from cybox.core import Observables import cybox.utils +logger = logging.getLogger(__name__) + def assert_equal_ignore(item1, item2, ignore_keys=None): """Recursively compare two dictionaries, ignoring differences in some keys. @@ -54,8 +55,8 @@ def round_trip(o, output=False, list_=False): klass = o.__class__ if output: - print("Class: ", klass) - print("-" * 40) + logger.debug("Class: {0}".format(klass)) + logger.debug("-" * 40) # 1. cybox.Entity -> dict/list if list_: @@ -67,8 +68,8 @@ def round_trip(o, output=False, list_=False): json_string = json.dumps(d) if output: - print(json_string) - print("-" * 40) + logger.debug(json_string) + logger.debug("-" * 40) # Before parsing the JSON, make sure the cache is clear cybox.utils.cache_clear() @@ -94,8 +95,8 @@ def round_trip(o, output=False, list_=False): xml_string = xml_string.decode(ExternalEncoding) if output: - print(xml_string) - print("-" * 40) + logger.debug(xml_string) + logger.debug("-" * 40) # Before parsing the XML, make sure the cache is clear cybox.utils.cache_clear() diff --git a/cybox/test/common/hash_test.py b/cybox/test/common/hash_test.py index 19cd704d..14d078d4 100644 --- a/cybox/test/common/hash_test.py +++ b/cybox/test/common/hash_test.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, The MITRE Corporation. All rights reserved. # See LICENSE.txt for complete terms. +import logging import unittest from mixbox.vendor.six import u @@ -8,6 +9,8 @@ from cybox.common import Hash, HashList, HashName, HexBinary import cybox.test +logger = logging.getLogger(__name__) + EMPTY_MD5 = u("d41d8cd98f00b204e9800998ecf8427e") EMPTY_SHA1 = u("da39a3ee5e6b4b0d3255bfef95601890afd80709") EMPTY_SHA224 = u("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f") @@ -174,10 +177,10 @@ def test_namespace_count(self): h.append(EMPTY_SHA256) h.append(EMPTY_SHA384) h.append(EMPTY_SHA512) - print(h.to_xml()) + logger.info(h.to_xml()) ns_list = cybox.test.round_trip(h, list_=True)._get_namespaces() - print(ns_list) + logger.info(ns_list) # Only "common" and "vocabs" should be here. "xsi" is only added later self.assertEqual(2, len(ns_list)) diff --git a/cybox/test/common/structured_test_text.py b/cybox/test/common/structured_test_text.py index dccb4974..e705dacd 100644 --- a/cybox/test/common/structured_test_text.py +++ b/cybox/test/common/structured_test_text.py @@ -3,7 +3,7 @@ import unittest -from mixbox.vendor.six import u +from mixbox.vendor.six import text_type, u from cybox.common import StructuredText import cybox.test @@ -38,7 +38,7 @@ def test_plain(self): def test_unicode(self): text = self.klass.from_dict(self._full_dict) # This should not raise any errors - print(text) + self.assertTrue(b"WARNING" in text_type(text).encode('utf-8')) if __name__ == "__main__": diff --git a/cybox/test/core/action_reference_test.py b/cybox/test/core/action_reference_test.py index 252e9fac..ad401a64 100644 --- a/cybox/test/core/action_reference_test.py +++ b/cybox/test/core/action_reference_test.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, The MITRE Corporation. All rights reserved. # See LICENSE.txt for complete terms. +import logging import unittest from mixbox.vendor.six import u @@ -8,6 +9,8 @@ from cybox.core import ActionReference from cybox.test import EntityTestCase +logger = logging.getLogger(__name__) + class TestActionReference(EntityTestCase, unittest.TestCase): klass = ActionReference @@ -17,8 +20,8 @@ class TestActionReference(EntityTestCase, unittest.TestCase): def test_construction(self): aref = ActionReference(action_id="example:Action-1") - print(aref.to_xml()) - print(aref.to_dict()) + logger.info(aref.to_xml()) + logger.info(aref.to_dict()) self.assertTrue(b"example:Action-1" in aref.to_xml()) self.assertTrue("example:Action-1" in aref.to_json()) diff --git a/cybox/test/core/object_test.py b/cybox/test/core/object_test.py index 54501724..b2c74ab3 100644 --- a/cybox/test/core/object_test.py +++ b/cybox/test/core/object_test.py @@ -1,17 +1,19 @@ # Copyright (c) 2015, The MITRE Corporation. All rights reserved. # See LICENSE.txt for complete terms. +import logging import unittest from mixbox.vendor.six import u -from cybox.core import Object, Observables, RelatedObject, Relationship +from cybox.core import Object, Observables, RelatedObject from cybox.objects.address_object import Address -from cybox.objects.email_message_object import EmailMessage from cybox.objects.uri_object import URI from cybox.test import EntityTestCase, round_trip, round_trip_dict from cybox.utils import CacheMiss, set_id_method +logger = logging.getLogger(__name__) + class ObjectTest(EntityTestCase, unittest.TestCase): klass = Object @@ -152,7 +154,7 @@ def test_relationship_vocabnameref(self): def _test_round_trip(self, observables): self.maxDiff = None - print(observables.to_xml()) + logger.info(observables.to_xml()) observables2 = round_trip(observables) self.assertEqual(observables.to_dict(), observables2.to_dict()) diff --git a/cybox/test/core/observable_test.py b/cybox/test/core/observable_test.py index 7e077517..f017ff42 100644 --- a/cybox/test/core/observable_test.py +++ b/cybox/test/core/observable_test.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, The MITRE Corporation. All rights reserved. # See LICENSE.txt for complete terms. +import logging import unittest from mixbox.vendor.six import u @@ -12,6 +13,8 @@ from cybox.objects.address_object import Address from cybox.test import EntityTestCase, round_trip +logger = logging.getLogger(__name__) + class TestObservable(EntityTestCase, unittest.TestCase): klass = Observable @@ -44,7 +47,7 @@ def test_keywords(self): self.assertTrue(b"eyword" not in o.to_xml()) o.add_keyword("Foo") - print(o.to_xml()) + logger.info(o.to_xml()) self.assertTrue(b"Foo" in o.to_xml()) o2 = round_trip(o) diff --git a/cybox/test/objects/email_message_test.py b/cybox/test/objects/email_message_test.py index 3db789ba..22a164a0 100644 --- a/cybox/test/objects/email_message_test.py +++ b/cybox/test/objects/email_message_test.py @@ -2,6 +2,7 @@ # See LICENSE.txt for complete terms. import datetime +import logging import unittest from mixbox.vendor.six import u @@ -17,6 +18,8 @@ from cybox.test import EntityTestCase from cybox.test.objects import ObjectTestCase +logger = logging.getLogger(__name__) + class TestLinks(EntityTestCase, unittest.TestCase): klass = LinkReference @@ -301,10 +304,10 @@ def test_get_namespaces(self): m.links.append(u.parent.id_) o = Observables([u, m]) - print(o.to_xml()) + logger.info(o.to_xml()) actual_namespaces = o._get_namespaces() - print("\n".join([str(x) for x in actual_namespaces])) + logger.info("\n".join([str(x) for x in actual_namespaces])) self.assertEqual(5, len(actual_namespaces))