3333
3434from tests .integration import PROTOCOL_VERSION , CASSANDRA_VERSION , greaterthanorequalcass30 , greaterthanorequalcass3_11
3535from tests .integration .cqlengine .base import BaseCassEngTestCase
36+ import pytest
3637
3738
3839class TestDatetime (BaseCassEngTestCase ):
@@ -90,7 +91,7 @@ def test_datetime_none(self):
9091
9192 def test_datetime_invalid (self ):
9293 dt_value = 'INVALID'
93- with self . assertRaises (TypeError ):
94+ with pytest . raises (TypeError ):
9495 self .DatetimeTest .objects .create (test_id = 4 , created_at = dt_value )
9596
9697 def test_datetime_timestamp (self ):
@@ -185,7 +186,7 @@ def test_varint_io(self):
185186 int2 = self .VarIntTest .objects (test_id = 0 ).first ()
186187 assert int1 .bignum == int2 .bignum
187188
188- with self . assertRaises (ValidationError ):
189+ with pytest . raises (ValidationError ):
189190 self .VarIntTest .objects .create (test_id = 0 , bignum = "not_a_number" )
190191
191192
@@ -541,22 +542,22 @@ def test_min_length(self):
541542 Ascii (min_length = 5 ).validate ('kevin' )
542543 Ascii (min_length = 5 ).validate ('kevintastic' )
543544
544- with self . assertRaises (ValidationError ):
545+ with pytest . raises (ValidationError ):
545546 Ascii (min_length = 1 ).validate ('' )
546547
547- with self . assertRaises (ValidationError ):
548+ with pytest . raises (ValidationError ):
548549 Ascii (min_length = 1 ).validate (None )
549550
550- with self . assertRaises (ValidationError ):
551+ with pytest . raises (ValidationError ):
551552 Ascii (min_length = 6 ).validate ('' )
552553
553- with self . assertRaises (ValidationError ):
554+ with pytest . raises (ValidationError ):
554555 Ascii (min_length = 6 ).validate (None )
555556
556- with self . assertRaises (ValidationError ):
557+ with pytest . raises (ValidationError ):
557558 Ascii (min_length = 6 ).validate ('kevin' )
558559
559- with self . assertRaises (ValueError ):
560+ with pytest . raises (ValueError ):
560561 Ascii (min_length = - 1 )
561562
562563 def test_max_length (self ):
@@ -573,13 +574,13 @@ def test_max_length(self):
573574 Ascii (max_length = 5 ).validate ('b' )
574575 Ascii (max_length = 5 ).validate ('blake' )
575576
576- with self . assertRaises (ValidationError ):
577+ with pytest . raises (ValidationError ):
577578 Ascii (max_length = 0 ).validate ('b' )
578579
579- with self . assertRaises (ValidationError ):
580+ with pytest . raises (ValidationError ):
580581 Ascii (max_length = 5 ).validate ('blaketastic' )
581582
582- with self . assertRaises (ValueError ):
583+ with pytest . raises (ValueError ):
583584 Ascii (max_length = - 1 )
584585
585586 def test_length_range (self ):
@@ -588,30 +589,30 @@ def test_length_range(self):
588589 Ascii (min_length = 10 , max_length = 10 )
589590 Ascii (min_length = 10 , max_length = 11 )
590591
591- with self . assertRaises (ValueError ):
592+ with pytest . raises (ValueError ):
592593 Ascii (min_length = 10 , max_length = 9 )
593594
594- with self . assertRaises (ValueError ):
595+ with pytest . raises (ValueError ):
595596 Ascii (min_length = 1 , max_length = 0 )
596597
597598 def test_type_checking (self ):
598599 Ascii ().validate ('string' )
599600 Ascii ().validate (u'unicode' )
600601 Ascii ().validate (bytearray ('bytearray' , encoding = 'ascii' ))
601602
602- with self . assertRaises (ValidationError ):
603+ with pytest . raises (ValidationError ):
603604 Ascii ().validate (5 )
604605
605- with self . assertRaises (ValidationError ):
606+ with pytest . raises (ValidationError ):
606607 Ascii ().validate (True )
607608
608609 Ascii ().validate ("!#$%&\' ()*+,-./" )
609610
610- with self . assertRaises (ValidationError ):
611+ with pytest . raises (ValidationError ):
611612 Ascii ().validate ('Beyonc' + chr (233 ))
612613
613614 if sys .version_info < (3 , 1 ):
614- with self . assertRaises (ValidationError ):
615+ with pytest . raises (ValidationError ):
615616 Ascii ().validate (u'Beyonc' + unichr (233 ))
616617
617618 def test_unaltering_validation (self ):
@@ -629,26 +630,26 @@ def test_required_validation(self):
629630 """ Tests that validation raise on none and blank values if value required. """
630631 Ascii (required = True ).validate ('k' )
631632
632- with self . assertRaises (ValidationError ):
633+ with pytest . raises (ValidationError ):
633634 Ascii (required = True ).validate ('' )
634635
635- with self . assertRaises (ValidationError ):
636+ with pytest . raises (ValidationError ):
636637 Ascii (required = True ).validate (None )
637638
638639 # With min_length set.
639640 Ascii (required = True , min_length = 0 ).validate ('k' )
640641 Ascii (required = True , min_length = 1 ).validate ('k' )
641642
642- with self . assertRaises (ValidationError ):
643+ with pytest . raises (ValidationError ):
643644 Ascii (required = True , min_length = 2 ).validate ('k' )
644645
645646 # With max_length set.
646647 Ascii (required = True , max_length = 1 ).validate ('k' )
647648
648- with self . assertRaises (ValidationError ):
649+ with pytest . raises (ValidationError ):
649650 Ascii (required = True , max_length = 2 ).validate ('kevin' )
650651
651- with self . assertRaises (ValueError ):
652+ with pytest . raises (ValueError ):
652653 Ascii (required = True , max_length = 0 )
653654
654655
@@ -668,22 +669,22 @@ def test_min_length(self):
668669 Text (min_length = 5 ).validate ('blake' )
669670 Text (min_length = 5 ).validate ('blaketastic' )
670671
671- with self . assertRaises (ValidationError ):
672+ with pytest . raises (ValidationError ):
672673 Text (min_length = 1 ).validate ('' )
673674
674- with self . assertRaises (ValidationError ):
675+ with pytest . raises (ValidationError ):
675676 Text (min_length = 1 ).validate (None )
676677
677- with self . assertRaises (ValidationError ):
678+ with pytest . raises (ValidationError ):
678679 Text (min_length = 6 ).validate ('' )
679680
680- with self . assertRaises (ValidationError ):
681+ with pytest . raises (ValidationError ):
681682 Text (min_length = 6 ).validate (None )
682683
683- with self . assertRaises (ValidationError ):
684+ with pytest . raises (ValidationError ):
684685 Text (min_length = 6 ).validate ('blake' )
685686
686- with self . assertRaises (ValueError ):
687+ with pytest . raises (ValueError ):
687688 Text (min_length = - 1 )
688689
689690 def test_max_length (self ):
@@ -700,13 +701,13 @@ def test_max_length(self):
700701 Text (max_length = 5 ).validate ('b' )
701702 Text (max_length = 5 ).validate ('blake' )
702703
703- with self . assertRaises (ValidationError ):
704+ with pytest . raises (ValidationError ):
704705 Text (max_length = 0 ).validate ('b' )
705706
706- with self . assertRaises (ValidationError ):
707+ with pytest . raises (ValidationError ):
707708 Text (max_length = 5 ).validate ('blaketastic' )
708709
709- with self . assertRaises (ValueError ):
710+ with pytest . raises (ValueError ):
710711 Text (max_length = - 1 )
711712
712713 def test_length_range (self ):
@@ -715,21 +716,21 @@ def test_length_range(self):
715716 Text (min_length = 10 , max_length = 10 )
716717 Text (min_length = 10 , max_length = 11 )
717718
718- with self . assertRaises (ValueError ):
719+ with pytest . raises (ValueError ):
719720 Text (min_length = 10 , max_length = 9 )
720721
721- with self . assertRaises (ValueError ):
722+ with pytest . raises (ValueError ):
722723 Text (min_length = 1 , max_length = 0 )
723724
724725 def test_type_checking (self ):
725726 Text ().validate ('string' )
726727 Text ().validate (u'unicode' )
727728 Text ().validate (bytearray ('bytearray' , encoding = 'ascii' ))
728729
729- with self . assertRaises (ValidationError ):
730+ with pytest . raises (ValidationError ):
730731 Text ().validate (5 )
731732
732- with self . assertRaises (ValidationError ):
733+ with pytest . raises (ValidationError ):
733734 Text ().validate (True )
734735
735736 Text ().validate ("!#$%&\' ()*+,-./" )
@@ -752,26 +753,26 @@ def test_required_validation(self):
752753 """ Tests that validation raise on none and blank values if value required. """
753754 Text (required = True ).validate ('b' )
754755
755- with self . assertRaises (ValidationError ):
756+ with pytest . raises (ValidationError ):
756757 Text (required = True ).validate ('' )
757758
758- with self . assertRaises (ValidationError ):
759+ with pytest . raises (ValidationError ):
759760 Text (required = True ).validate (None )
760761
761762 # With min_length set.
762763 Text (required = True , min_length = 0 ).validate ('b' )
763764 Text (required = True , min_length = 1 ).validate ('b' )
764765
765- with self . assertRaises (ValidationError ):
766+ with pytest . raises (ValidationError ):
766767 Text (required = True , min_length = 2 ).validate ('b' )
767768
768769 # With max_length set.
769770 Text (required = True , max_length = 1 ).validate ('b' )
770771
771- with self . assertRaises (ValidationError ):
772+ with pytest . raises (ValidationError ):
772773 Text (required = True , max_length = 2 ).validate ('blake' )
773774
774- with self . assertRaises (ValueError ):
775+ with pytest . raises (ValueError ):
775776 Text (required = True , max_length = 0 )
776777
777778
@@ -781,7 +782,7 @@ class TestModel(Model):
781782 id = UUID (primary_key = True , default = uuid4 )
782783
783784 def test_extra_field (self ):
784- with self . assertRaises (ValidationError ):
785+ with pytest . raises (ValidationError ):
785786 self .TestModel .create (bacon = 5000 )
786787
787788
@@ -834,5 +835,5 @@ def test_inet_saves(self):
834835
835836 def test_non_address_fails (self ):
836837 # TODO: presently this only tests that the server blows it up. Is there supposed to be local validation?
837- with self . assertRaises (InvalidRequest ):
838+ with pytest . raises (InvalidRequest ):
838839 self .InetTestModel .create (address = "what is going on here?" )
0 commit comments