From 5e9de401e3bb9f94fffbdfbbba1c80f434a89009 Mon Sep 17 00:00:00 2001 From: Gustavo Narea Date: Wed, 18 Feb 2015 14:48:52 +0000 Subject: [PATCH] Added missing copyright notices and removed superfluous whitespace --- tests/test_generic_utils.py | 28 +++++++++--- tests/test_record.py | 90 +++++++++++++++++++++---------------- tests/test_record_type.py | 28 +++++++++--- 3 files changed, 94 insertions(+), 52 deletions(-) diff --git a/tests/test_generic_utils.py b/tests/test_generic_utils.py index 75bf2da..8f52d9b 100644 --- a/tests/test_generic_utils.py +++ b/tests/test_generic_utils.py @@ -1,3 +1,17 @@ +# Copyright 2013-2015, Gustavo Narea. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from nose.tools import assert_false from nose.tools import eq_ from nose.tools import ok_ @@ -7,29 +21,29 @@ class TestDuplicatedIterableItems(object): - + def test_no_items(self): original_iterable = [] duplicated_items = get_duplicated_iterable_items(original_iterable) eq_(0, len(duplicated_items)) - + def test_unique_items(self): original_iterable = [1, 2, 3] duplicated_items = get_duplicated_iterable_items(original_iterable) eq_(0, len(duplicated_items)) - + def test_one_duplicate(self): original_iterable = [1, 2, 2] duplicated_items = get_duplicated_iterable_items(original_iterable) eq_(1, len(duplicated_items)) ok_(2 in duplicated_items) - + def test_two_duplicates_of_same_item(self): original_iterable = [1, 2, 2, 2] duplicated_items = get_duplicated_iterable_items(original_iterable) eq_(1, len(duplicated_items)) ok_(2 in duplicated_items) - + def test_duplicates_of_various_items(self): original_iterable = [1, 1, 2, 2] duplicated_items = get_duplicated_iterable_items(original_iterable) @@ -39,7 +53,7 @@ def test_duplicates_of_various_items(self): class TestPythonIdentifierCheck(object): - + def test_valid_identifiers(self): valid_identifiers = ( "_", @@ -52,7 +66,7 @@ def test_valid_identifiers(self): ) for identifier in valid_identifiers: ok_(is_valid_python_identifier(identifier), identifier) - + def test_invalid_identifiers(self): invalid_identifiers = ( "", diff --git a/tests/test_record.py b/tests/test_record.py index 067ff27..d7409fa 100644 --- a/tests/test_record.py +++ b/tests/test_record.py @@ -1,3 +1,17 @@ +# Copyright 2013-2015, Gustavo Narea. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from pickle import dumps as pickle_serialize from pickle import loads as pickle_deserialize @@ -16,41 +30,41 @@ class TestInitialization(object): - + def test_initialization(self): my_point = Point(1, 3) ok_(isinstance(my_point, Point)) eq_(my_point.coordinate_x, 1) eq_(my_point.coordinate_y, 3) - + def test_initialization_by_name(self): my_point = Point(coordinate_x=1, coordinate_y=3) eq_(my_point.coordinate_x, 1) eq_(my_point.coordinate_y, 3) - + def test_subtype(self): my_point_3d = Point3D(1, 3, 5) eq_(my_point_3d.coordinate_x, 1) eq_(my_point_3d.coordinate_y, 3) eq_(my_point_3d.coordinate_z, 5) - + def test_overriding_default_field_value(self): Point = Record.create_type("Point", "coordinate_x", coordinate_x=2) my_point = Point(1) eq_(my_point.coordinate_x, 1) - + def test_skipping_field_with_default_value(self): Point = Record.create_type("Point", "coordinate_x", coordinate_x=2) my_point = Point() eq_(my_point.coordinate_x, 2) - + def test_skipping_field_without_default_value(self): assert_raises_regexp( RecordInstanceError, '^Field "coordinate_x" is undefined$', Point, ) - + def test_setting_unknown_field(self): # By position assert_raises_regexp( @@ -60,7 +74,7 @@ def test_setting_unknown_field(self): 1, 3, 0, - -1, + - 1, ) # By name assert_raises_regexp( @@ -71,7 +85,7 @@ def test_setting_unknown_field(self): 3, coordinate_z=0, ) - + def test_field_value_set_multiple_times(self): assert_raises_regexp( RecordInstanceError, @@ -81,24 +95,24 @@ def test_field_value_set_multiple_times(self): 3, coordinate_x=2, ) - + def test_copy(self): original_point = Point(1, 3) - + derived_point = original_point.copy() derived_point.coordinate_y = 5 - + eq_(original_point.coordinate_x, derived_point.coordinate_x) eq_(3, original_point.coordinate_y) eq_(5, derived_point.coordinate_y) - + def test_generalization(self): my_point_3d = Point3D(1, 3, 5) my_point = Point.init_from_specialization(my_point_3d) ok_(isinstance(my_point, Point)) eq_(my_point.coordinate_x, my_point_3d.coordinate_x) eq_(my_point.coordinate_y, my_point_3d.coordinate_y) - + def test_invalid_generalization(self): my_point = Point(1, 3) assert_raises_regexp( @@ -107,7 +121,7 @@ def test_invalid_generalization(self): Point3D.init_from_specialization, my_point, ) - + def test_specialization(self): my_point = Point(1, 3) my_point_3d = Point3D.init_from_generalization(my_point, coordinate_z=5) @@ -115,7 +129,7 @@ def test_specialization(self): eq_(my_point_3d.coordinate_x, my_point.coordinate_x) eq_(my_point_3d.coordinate_y, my_point.coordinate_y) eq_(my_point_3d.coordinate_z, 5) - + def test_invalid_specialization(self): my_point_3d = Point3D(1, 3, 5) assert_raises_regexp( @@ -124,7 +138,7 @@ def test_invalid_specialization(self): Point.init_from_generalization, my_point_3d, ) - + def test_incomplete_specialization(self): my_point = Point(1, 3) assert_raises_regexp( @@ -133,7 +147,7 @@ def test_incomplete_specialization(self): Point3D.init_from_generalization, my_point, ) - + def test_specialization_overriding_field_values(self): my_point = Point(1, 3) assert_raises_regexp( @@ -147,66 +161,66 @@ def test_specialization_overriding_field_values(self): class TestComparison(object): - + def test_same_type_and_same_field_values(self): point1 = Point(1, 3) point2 = Point(1, 3) self.assert_equals(point1, point2) - + def test_same_type_and_different_field_values(self): point1 = Point(2, 4) point2 = Point(6, 8) self.assert_not_equals(point1, point2) - + def test_different_type_and_same_field_values(self): point = Point(2, 4) - + AlternativePoint = Record.create_type( "AlternativePoint", "coordinate_x", "coordinate_y", ) alternative_point = AlternativePoint(2, 4) - + self.assert_not_equals(point, alternative_point) - + def test_specialization(self): point = Point(2, 4) point_3d = Point3D(2, 4, 8) self.assert_not_equals(point, point_3d) - + def test_non_record(self): point = Point(1, 3) self.assert_not_equals(point, object()) - + #{ Check equality in all possible ways - + # In Python, "a == b = True" DOESN'T necessarily mean that "a != b = False" # nor "b == a = True". - + @staticmethod def assert_equals(item1, item2): ok_(item1 == item2) ok_(item2 == item1) assert_false(item1 != item2) assert_false(item2 != item1) - + @staticmethod def assert_not_equals(item1, item2): ok_(item1 != item2) ok_(item2 != item1) assert_false(item1 == item2) assert_false(item2 == item1) - + #} class TestFieldAccess(object): - + def test_getting_valid_field(self): point = Point(1, 3) eq_(1, point.coordinate_x) - + def test_getting_invalid_field(self): point = Point(1, 3) assert_raises_regexp( @@ -216,28 +230,28 @@ def test_getting_invalid_field(self): point, "coordinate_z", ) - + def test_getting_all_field_values(self): point = Point(1, 3) expected_values = {'coordinate_x': 1, 'coordinate_y': 3} actual_values = point.get_field_values() eq_(expected_values, actual_values) - + actual_values['coordinate_x'] = 7 eq_(1, point.coordinate_x, "The field values must've been copied") - + def test_setting_valid_field(self): point = Point(1, 3) point.coordinate_x = 5 - + # Ensure it wasn't just set on __dict__ field_values = point.get_field_values() eq_(5, field_values['coordinate_x']) - + def test_setting_invalid_field(self): point = Point(1, 3) point.coordinate_z = 5 - + # Ensure it wasn't set on __dict__ field_values = point.get_field_values() assert_not_in("coordinate_z", field_values) diff --git a/tests/test_record_type.py b/tests/test_record_type.py index c1e3481..64b03ca 100644 --- a/tests/test_record_type.py +++ b/tests/test_record_type.py @@ -1,3 +1,17 @@ +# Copyright 2013-2015, Gustavo Narea. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from nose.tools import assert_not_equals from nose.tools import assert_raises_regexp from nose.tools import eq_ @@ -30,7 +44,7 @@ def test_creation_with_ilegal_type_name(): Record.create_type, "Invalid-Name", ) - + # Subtype Point = Record.create_type("Point", "coordinate_x", "coordinate_y") assert_raises_regexp( @@ -50,7 +64,7 @@ def test_creation_with_ilegal_field_name(): "Point", "coordinate-x", ) - + # Subtype Point = Record.create_type("Point", "coordinate_x", "coordinate_y") assert_raises_regexp( @@ -72,7 +86,7 @@ def test_creation_with_duplicated_field_names(): "coordinate_x", "coordinate_x", ) - + # Multiple fields duplicated assert_raises_regexp( RecordTypeError, @@ -85,7 +99,7 @@ def test_creation_with_duplicated_field_names(): "coordinate_x", "coordinate_y", ) - + # Subtype Point = Record.create_type("Point", "coordinate_x", "coordinate_y") assert_raises_regexp( @@ -96,7 +110,7 @@ def test_creation_with_duplicated_field_names(): "coordinate_z", "coordinate_z", ) - + # Subtype redefining field in supertype Point = Record.create_type("Point", "coordinate_x", "coordinate_y") assert_raises_regexp( @@ -113,7 +127,7 @@ def test_getting_field_names(): # Supertype Point = Record.create_type("Point", "coordinate_x", "coordinate_y") eq_(("coordinate_x", "coordinate_y"), Point.field_names) - + # Subtype Point3D = Point.extend_type("Point3D", "coordinate_z") eq_(("coordinate_x", "coordinate_y", "coordinate_z"), Point3D.field_names) @@ -129,7 +143,7 @@ def test_default_value_for_undefined_field(): "coordinate_x", weight=3, ) - + # Subtype Point = Record.create_type("Point", "coordinate_x", "coordinate_y") assert_raises_regexp(