def test__validate_kwargs_invanild_kwarg_type(self): """Test pseudo private method.""" with self.assertRaisesRegexp( SdlSyntaxException, ' '.join([ 'Value of KW Argument adaptive is expected', 'to be type String but got Vector' ])): self.sut = SceneItem('foo', [], [], {'adaptive': (1, 2, 3)}) self.sut._validate_kwargs({'adaptive': 'String'})
def test__check_kwarg_value_invalid_value(self): """Test pseudo private method.""" self.sut = SceneItem('foo', [], [], {'baz': 'bar'}) with self.assertRaisesRegexp( SdlSyntaxException, 'Value of KW Argument baz is expected to be in .* but got bar' ): self.sut._checkKwargValue('baz', ['foo'])
def test__validate_kwargs_invanild_kwarg(self): """Test pseudo private method.""" with self.assertRaisesRegexp( SdlSyntaxException, 'Keyword agate not allowed for object SceneItem'): self.sut = SceneItem('foo', [], [], { 'adaptive': (1, 2, 3), 'agate': SceneItem('bar') }) self.sut._validate_kwargs({'boo': 'Vector'})
def test_create_with_options(self): """Test creation and inheritance.""" self.sut = SceneItem('foo', [], [(1, 2, 3), SceneItem('bar')]) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, [Vector(1, 2, 3), SceneItem('bar')]) self.assertEqual(type(self.sut.kwargs), dict) self.assertEqual(self.sut.kwargs, {})
def test_setitem_replaces_opt(self): """Test magic method.""" self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) # before self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 5, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7}) self.sut[4] = 0 # after self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 0, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7})
def test_getitem(self): ''' Test magic method ''' self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) self.assertEqual(self.sut[1], 2) self.assertEqual(self.sut[4], 5)
def test_append(self): """Test sut.append().""" second = SceneItem('bar') self.sut.append([second]) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, [second]) self.assertIn(second, self.sut.opts)
def test_append_with_kwarg(self): """Test sut.append().""" item = SceneItem('bar') self.sut.append(baz=item) self.assertEqual(type(self.sut.kwargs), dict) self.assertEqual(self.sut.kwargs, {'baz': item}) self.assertIn('baz', self.sut.kwargs)
def test__check_kwarg_value_invalid_value(self): ''' Test pseudo private method ''' self.sut = SceneItem('foo', [], [], {'baz': 'bar'}) with self.assertRaisesRegexp( SdlSyntaxException, 'Value of KW Argument baz is expectet to be in .* but got bar' ): self.sut._checkKwargValue('baz', ['foo'])
def test__validate_kwargs_invanild_kwarg(self): ''' Test pseudo private method ''' with self.assertRaisesRegexp( SdlSyntaxException, 'Keyword agate not allowed for object SceneItem' ): self.sut = SceneItem( 'foo', [], [], {'adaptive': (1, 2, 3), 'agate': SceneItem('bar')} ) self.sut._validate_kwargs({'boo': 'Vector'})
def test_setitem_replaces_arg(self): ''' Test magic method ''' self.sut = SceneItem("foo", [SceneItem("bar")]) other = SceneItem("foo", [SceneItem("baz")]) self.sut[0] = SceneItem('baz') self.assertEqual( self.sut, other )
def test__validate_kwargs_invanild_kwarg_type(self): ''' Test pseudo private method ''' with self.assertRaisesRegexp( SdlSyntaxException, ' '.join([ 'Value of KW Argument adaptive is expectet', 'to be type String but got Vector' ]) ): self.sut = SceneItem('foo', [], [], {'adaptive': (1, 2, 3)}) self.sut._validate_kwargs({'adaptive': 'String'})
def test_setitem_replaces_arg(self): """Test magic method.""" self.sut = SceneItem("foo", [SceneItem("bar")]) other = SceneItem("foo", [SceneItem("baz")]) self.sut[0] = SceneItem('baz') self.assertEqual(self.sut, other)
def test_create_with_kwargs(self): """Test creation and inheritance.""" self.sut = SceneItem('foo', [], [], { 'bar': (1, 2, 3), 'baz': SceneItem('bar') }) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, []) self.assertEqual(type(self.sut.kwargs), dict) self.assertIn('bar', self.sut.kwargs) warn(str(Vector(1, 2, 3))) warn(str(self.sut.kwargs['bar'])) self.assertEqual(Vector(1, 2, 3), self.sut.kwargs['bar']) self.assertIn('baz', self.sut.kwargs) self.assertEqual(SceneItem('bar'), self.sut.kwargs['baz'])
def test_setitem_replaces_opt(self): ''' Test magic method ''' self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) #before self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 5, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7}) self.sut[4] = 0 #after self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 0, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7})
def test_create_with_options(self): ''' Test creation and inheritance ''' self.sut = SceneItem('foo', [], [(1, 2, 3), SceneItem('bar')]) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual( self.sut.opts, [Vector(1, 2, 3), SceneItem('bar')] ) self.assertEqual(type(self.sut.kwargs), dict) self.assertEqual(self.sut.kwargs, {})
def test_create_with_kwargs(self): ''' Test creation and inheritance ''' self.sut = SceneItem( 'foo', [], [], {'bar': (1, 2, 3), 'baz': SceneItem('bar')} ) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, []) self.assertEqual(type(self.sut.kwargs), dict) self.assertIn('bar', self.sut.kwargs) warn(str(Vector(1, 2, 3))) warn(str(self.sut.kwargs['bar'])) self.assertEqual(Vector(1, 2, 3), self.sut.kwargs['bar']) self.assertIn('baz', self.sut.kwargs) self.assertEqual(SceneItem('bar'), self.sut.kwargs['baz'])
def setUp(self): ''' Set up fixture ''' self.sut = SceneItem('foo')
class SceneItemTestCase(unittest.TestCase): ''' Tests for SceneItem class ''' def setUp(self): ''' Set up fixture ''' self.sut = SceneItem('foo') def test_creation(self): ''' Test creation and inheritance ''' self.assertIsInstance(self.sut, SceneItem) def test_to_string(self): ''' Test sut.__str__() ''' second = 'foo' self.assertEqual(str(self.sut), second) def test_append(self): ''' Test sut.append() ''' second = SceneItem('bar') self.sut.append([second]) self.assertEqual( type(self.sut.opts), list ) self.assertEqual( self.sut.opts, [second] ) self.assertIn( second, self.sut.opts ) def test_append_with_kwarg(self): ''' Test sut.append() ''' item = SceneItem('bar') self.sut.append(baz=item) self.assertEqual( type(self.sut.kwargs), dict ) self.assertEqual( self.sut.kwargs, {'baz': item} ) self.assertIn( 'baz', self.sut.kwargs ) def test_flatten(self): ''' Test sut.flatten() ''' first = self.sut.flatten([1, [1, 2], 3, 4]) self.assertEqual(first, [1, 1, 2, 3, 4]) def test_create_with_options(self): ''' Test creation and inheritance ''' self.sut = SceneItem('foo', [], [(1, 2, 3), SceneItem('bar')]) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual( self.sut.opts, [Vector(1, 2, 3), SceneItem('bar')] ) self.assertEqual(type(self.sut.kwargs), dict) self.assertEqual(self.sut.kwargs, {}) def test_create_with_kwargs(self): ''' Test creation and inheritance ''' self.sut = SceneItem( 'foo', [], [], {'bar': (1, 2, 3), 'baz': SceneItem('bar')} ) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, []) self.assertEqual(type(self.sut.kwargs), dict) self.assertIn('bar', self.sut.kwargs) warn(str(Vector(1, 2, 3))) warn(str(self.sut.kwargs['bar'])) self.assertEqual(Vector(1, 2, 3), self.sut.kwargs['bar']) self.assertIn('baz', self.sut.kwargs) self.assertEqual(SceneItem('bar'), self.sut.kwargs['baz']) def test_setitem_replaces_arg(self): ''' Test magic method ''' self.sut = SceneItem("foo", [SceneItem("bar")]) other = SceneItem("foo", [SceneItem("baz")]) self.sut[0] = SceneItem('baz') self.assertEqual( self.sut, other ) def test_setitem_nonexisting_index(self): ''' Test magic method ''' with self.assertRaisesRegexp(IndexError, ''): self.sut[2] = SceneItem('baz') def test_block_end_zero_indentation(self): ''' Test pseudo private method ''' self.assertEqual(self.sut._block_end(), os.linesep) def test_setitem_replaces_opt(self): ''' Test magic method ''' self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) #before self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 5, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7}) self.sut[4] = 0 #after self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 0, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7}) def test_getitem(self): ''' Test magic method ''' self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) self.assertEqual(self.sut[1], 2) self.assertEqual(self.sut[4], 5) def test_getitem_raises_index_error(self): ''' Test magic method ''' with self.assertRaisesRegexp(IndexError, ''): warn(str(self.sut[2])) def test__dedent_below_zero(self): ''' Test pseudo private method ''' with self.assertRaisesRegexp( IllegalStateException, 'Indentation below zero' ): self.sut._dedent() def test__validate_kwargs_invanild_kwarg(self): ''' Test pseudo private method ''' with self.assertRaisesRegexp( SdlSyntaxException, 'Keyword agate not allowed for object SceneItem' ): self.sut = SceneItem( 'foo', [], [], {'adaptive': (1, 2, 3), 'agate': SceneItem('bar')} ) self.sut._validate_kwargs({'boo': 'Vector'}) def test__validate_kwargs_invanild_kwarg_type(self): ''' Test pseudo private method ''' with self.assertRaisesRegexp( SdlSyntaxException, ' '.join([ 'Value of KW Argument adaptive is expectet', 'to be type String but got Vector' ]) ): self.sut = SceneItem('foo', [], [], {'adaptive': (1, 2, 3)}) self.sut._validate_kwargs({'adaptive': 'String'}) def test__is_valid_identifier(self): ''' Test pseudo private method ''' self.assertTrue( self.sut._is_valid_identifier('foobar'), msg='Valid Identifier' ) self.assertFalse( self.sut._is_valid_identifier('agate'), msg='Invalid Identifier' ) def test___eq__WrongType(self): ''' Test magic method ''' with self.assertRaisesRegexp( TypeError, 'can only be compared to objects of same type' ): if self.sut == 3: pass def test__check_kwarg_value_invalid_value(self): ''' Test pseudo private method ''' self.sut = SceneItem('foo', [], [], {'baz': 'bar'}) with self.assertRaisesRegexp( SdlSyntaxException, 'Value of KW Argument baz is expectet to be in .* but got bar' ): self.sut._checkKwargValue('baz', ['foo'])
def test_getitem(self): """Test magic method.""" self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) self.assertEqual(self.sut[1], 2) self.assertEqual(self.sut[4], 5)
def test_equals_no_vector(self): """Test magic method.""" self.assertNotEqual(self.sut, SceneItem('bar'))
class SceneItemTestCase(unittest.TestCase): """Tests for SceneItem class.""" def setUp(self): """@Todo: DocString.""" self.sut = SceneItem('foo') def test_creation(self): """@Todo: DocString.""" self.assertIsInstance(self.sut, SceneItem) def test_to_string(self): """@Todo: DocString.""" second = 'foo' self.assertEqual(str(self.sut), second) def test_append(self): """Test sut.append().""" second = SceneItem('bar') self.sut.append([second]) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, [second]) self.assertIn(second, self.sut.opts) def test_append_with_kwarg(self): """Test sut.append().""" item = SceneItem('bar') self.sut.append(baz=item) self.assertEqual(type(self.sut.kwargs), dict) self.assertEqual(self.sut.kwargs, {'baz': item}) self.assertIn('baz', self.sut.kwargs) def test_flatten(self): """Test sut.flatten().""" first = self.sut.flatten([1, [1, 2], 3, 4]) self.assertEqual(first, [1, 1, 2, 3, 4]) def test_create_with_options(self): """Test creation and inheritance.""" self.sut = SceneItem('foo', [], [(1, 2, 3), SceneItem('bar')]) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, [Vector(1, 2, 3), SceneItem('bar')]) self.assertEqual(type(self.sut.kwargs), dict) self.assertEqual(self.sut.kwargs, {}) def test_create_with_kwargs(self): """Test creation and inheritance.""" self.sut = SceneItem('foo', [], [], { 'bar': (1, 2, 3), 'baz': SceneItem('bar') }) self.assertEqual(type(self.sut.args), list) self.assertEqual(self.sut.args, []) self.assertEqual(type(self.sut.opts), list) self.assertEqual(self.sut.opts, []) self.assertEqual(type(self.sut.kwargs), dict) self.assertIn('bar', self.sut.kwargs) warn(str(Vector(1, 2, 3))) warn(str(self.sut.kwargs['bar'])) self.assertEqual(Vector(1, 2, 3), self.sut.kwargs['bar']) self.assertIn('baz', self.sut.kwargs) self.assertEqual(SceneItem('bar'), self.sut.kwargs['baz']) def test_setitem_replaces_arg(self): """Test magic method.""" self.sut = SceneItem("foo", [SceneItem("bar")]) other = SceneItem("foo", [SceneItem("baz")]) self.sut[0] = SceneItem('baz') self.assertEqual(self.sut, other) def test_setitem_nonexisting_index(self): """Test magic method.""" with self.assertRaisesRegexp(IndexError, ''): self.sut[2] = SceneItem('baz') def test_block_end_zero_indentation(self): """Test pseudo private method.""" self.assertEqual(self.sut._block_end(), os.linesep) def test_setitem_replaces_opt(self): """Test magic method.""" self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) # before self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 5, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7}) self.sut[4] = 0 # after self.assertEqual(self.sut.args, [1, 2, 3]) self.assertEqual(self.sut.opts, [4, 0, 6]) self.assertEqual(self.sut.kwargs, {'bar': 7}) def test_getitem(self): """Test magic method.""" self.sut = SceneItem('foo', [1, 2, 3], [4, 5, 6], {'bar': 7}) self.assertEqual(self.sut[1], 2) self.assertEqual(self.sut[4], 5) def test_getitem_raises_index_error(self): """Test magic method.""" with self.assertRaisesRegexp(IndexError, ''): warn(str(self.sut[2])) def test__dedent_below_zero(self): """Test pseudo private method.""" with self.assertRaisesRegexp(IllegalStateException, 'Indentation below zero'): self.sut._dedent() def test__validate_kwargs_invanild_kwarg(self): """Test pseudo private method.""" with self.assertRaisesRegexp( SdlSyntaxException, 'Keyword agate not allowed for object SceneItem'): self.sut = SceneItem('foo', [], [], { 'adaptive': (1, 2, 3), 'agate': SceneItem('bar') }) self.sut._validate_kwargs({'boo': 'Vector'}) def test__validate_kwargs_invanild_kwarg_type(self): """Test pseudo private method.""" with self.assertRaisesRegexp( SdlSyntaxException, ' '.join([ 'Value of KW Argument adaptive is expected', 'to be type String but got Vector' ])): self.sut = SceneItem('foo', [], [], {'adaptive': (1, 2, 3)}) self.sut._validate_kwargs({'adaptive': 'String'}) def test__is_valid_identifier(self): """Test pseudo private method.""" self.assertTrue(self.sut._is_valid_identifier('foobar'), msg='Valid Identifier') self.assertFalse(self.sut._is_valid_identifier('agate'), msg='Invalid Identifier') def test___eq__wrong_type(self): """Test magic method.""" with self.assertRaisesRegexp( TypeError, 'can only be compared to objects of same type'): if self.sut == 3: pass def test__check_kwarg_value_invalid_value(self): """Test pseudo private method.""" self.sut = SceneItem('foo', [], [], {'baz': 'bar'}) with self.assertRaisesRegexp( SdlSyntaxException, 'Value of KW Argument baz is expected to be in .* but got bar' ): self.sut._checkKwargValue('baz', ['foo'])
def setUp(self): """@Todo: DocString.""" self.sut = SceneItem('foo')
def setUp(self): """Set up fixture.""" self.sut = SceneFile('test.pov', SceneItem('foo'), SceneItem('bar'))
def test_append(self): """Test sut.append().""" item = SceneItem('baz') self.sut.append(item) self.assertIn(item, self.sut.items)
def test_create_fnam_wrong_type(self): """Test Filename String expected but got int.""" with self.assertRaisesRegexp(TypeError, 'Filename String expected but got int'): self.sut = SceneFile(0, SceneItem('foo'), SceneItem('bar'))
def test_setitem_nonexisting_index(self): """Test magic method.""" with self.assertRaisesRegexp(IndexError, ''): self.sut[2] = SceneItem('baz')