<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import datetime <EOL> from django . db import connection <EOL> from django . db . models import F <EOL> from django . test import TestCase , Approximate , skipUnlessDBFeature <EOL> from . models import Number , Experiment <EOL> class ExpressionsRegressTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> Number ( integer = - <NUM_LIT:1> ) . save ( ) <EOL> Number ( integer = <NUM_LIT> ) . save ( ) <EOL> Number ( integer = <NUM_LIT> ) . save ( ) <EOL> self . assertEqual ( Number . objects . update ( float = F ( '<STR_LIT>' ) ) , <NUM_LIT:3> ) <EOL> def test_fill_with_value_from_same_object ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . all ( ) , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> ordered = False <EOL> ) <EOL> def test_increment_value ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> Number . objects . filter ( integer__gt = <NUM_LIT:0> ) <EOL> . update ( integer = F ( '<STR_LIT>' ) + <NUM_LIT:1> ) , <EOL> <NUM_LIT:2> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . all ( ) , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> ordered = False <EOL> ) <EOL> def test_filter_not_equals_other_field ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <EOL> Number . objects . filter ( integer__gt = <NUM_LIT:0> ) <EOL> . update ( integer = F ( '<STR_LIT>' ) + <NUM_LIT:1> ) , <EOL> <NUM_LIT:2> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . exclude ( float = F ( '<STR_LIT>' ) ) , <EOL> [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> ordered = False <EOL> ) <EOL> def test_complex_expressions ( self ) : <EOL> """<STR_LIT>""" <EOL> n = Number . objects . create ( integer = <NUM_LIT:10> , float = <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . filter ( pk = n . pk ) <EOL> . update ( float = F ( '<STR_LIT>' ) + F ( '<STR_LIT:float>' ) * <NUM_LIT:2> ) , <EOL> <NUM_LIT:1> ) <EOL> self . assertEqual ( Number . objects . get ( pk = n . pk ) . integer , <NUM_LIT:10> ) <EOL> self . assertEqual ( Number . objects . get ( pk = n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> class ExpressionOperatorTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . n = Number . objects . create ( integer = <NUM_LIT> , float = <NUM_LIT> ) <EOL> def test_lefthand_addition ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( <EOL> integer = F ( '<STR_LIT>' ) + <NUM_LIT:15> , <EOL> float = F ( '<STR_LIT:float>' ) + <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_lefthand_subtraction ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = F ( '<STR_LIT>' ) - <NUM_LIT:15> , <EOL> float = F ( '<STR_LIT:float>' ) - <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( - <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_lefthand_multiplication ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = F ( '<STR_LIT>' ) * <NUM_LIT:15> , <EOL> float = F ( '<STR_LIT:float>' ) * <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_lefthand_division ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = F ( '<STR_LIT>' ) / <NUM_LIT:2> , <EOL> float = F ( '<STR_LIT:float>' ) / <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_lefthand_modulo ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = F ( '<STR_LIT>' ) % <NUM_LIT:20> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT:2> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_lefthand_bitwise_and ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = F ( '<STR_LIT>' ) . bitand ( <NUM_LIT> ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_lefthand_bitwise_or ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = F ( '<STR_LIT>' ) . bitor ( <NUM_LIT> ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_right_hand_addition ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = <NUM_LIT:15> + F ( '<STR_LIT>' ) , <EOL> float = <NUM_LIT> + F ( '<STR_LIT:float>' ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_right_hand_subtraction ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = <NUM_LIT:15> - F ( '<STR_LIT>' ) , <EOL> float = <NUM_LIT> - F ( '<STR_LIT:float>' ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , - <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_right_hand_multiplication ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = <NUM_LIT:15> * F ( '<STR_LIT>' ) , <EOL> float = <NUM_LIT> * F ( '<STR_LIT:float>' ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_right_hand_division ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = <NUM_LIT> / F ( '<STR_LIT>' ) , <EOL> float = <NUM_LIT> / F ( '<STR_LIT:float>' ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT:15> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> def test_right_hand_modulo ( self ) : <EOL> Number . objects . filter ( pk = self . n . pk ) . update ( integer = <NUM_LIT> % F ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . integer , <NUM_LIT> ) <EOL> self . assertEqual ( Number . objects . get ( pk = self . n . pk ) . float , Approximate ( <NUM_LIT> , places = <NUM_LIT:3> ) ) <EOL> class FTimeDeltaTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> sday = datetime . date ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> ) <EOL> stime = datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:15> , <NUM_LIT:30> , <NUM_LIT> ) <EOL> midnight = datetime . time ( <NUM_LIT:0> ) <EOL> delta0 = datetime . timedelta ( <NUM_LIT:0> ) <EOL> delta1 = datetime . timedelta ( microseconds = <NUM_LIT> ) <EOL> delta2 = datetime . timedelta ( seconds = <NUM_LIT> ) <EOL> delta3 = datetime . timedelta ( hours = <NUM_LIT> , minutes = <NUM_LIT:8> ) <EOL> delta4 = datetime . timedelta ( days = <NUM_LIT:10> ) <EOL> self . deltas = [ ] <EOL> self . delays = [ ] <EOL> self . days_long = [ ] <EOL> end = stime + delta0 <EOL> e0 = Experiment . objects . create ( name = '<STR_LIT>' , assigned = sday , start = stime , <EOL> end = end , completed = end . date ( ) ) <EOL> self . deltas . append ( delta0 ) <EOL> self . delays . append ( e0 . start - <EOL> datetime . datetime . combine ( e0 . assigned , midnight ) ) <EOL> self . days_long . append ( e0 . completed - e0 . assigned ) <EOL> if connection . features . supports_microsecond_precision : <EOL> delay = datetime . timedelta ( <NUM_LIT:1> ) <EOL> end = stime + delay + delta1 <EOL> e1 = Experiment . objects . create ( name = '<STR_LIT>' , assigned = sday , <EOL> start = stime + delay , end = end , completed = end . date ( ) ) <EOL> self . deltas . append ( delta1 ) <EOL> self . delays . append ( e1 . start - <EOL> datetime . datetime . combine ( e1 . assigned , midnight ) ) <EOL> self . days_long . append ( e1 . completed - e1 . assigned ) <EOL> end = stime + delta2 <EOL> e2 = Experiment . objects . create ( name = '<STR_LIT>' , <EOL> assigned = sday - datetime . timedelta ( <NUM_LIT:3> ) , start = stime , end = end , <EOL> completed = end . date ( ) ) <EOL> self . deltas . append ( delta2 ) <EOL> self . delays . append ( e2 . start - <EOL> datetime . datetime . combine ( e2 . assigned , midnight ) ) <EOL> self . days_long . append ( e2 . completed - e2 . assigned ) <EOL> delay = datetime . timedelta ( <NUM_LIT:4> ) <EOL> end = stime + delay + delta3 <EOL> e3 = Experiment . objects . create ( name = '<STR_LIT>' , <EOL> assigned = sday , start = stime + delay , end = end , completed = end . date ( ) ) <EOL> self . deltas . append ( delta3 ) <EOL> self . delays . append ( e3 . start - <EOL> datetime . datetime . combine ( e3 . assigned , midnight ) ) <EOL> self . days_long . append ( e3 . completed - e3 . assigned ) <EOL> end = stime + delta4 <EOL> e4 = Experiment . objects . create ( name = '<STR_LIT>' , <EOL> assigned = sday - datetime . timedelta ( <NUM_LIT:10> ) , start = stime , end = end , <EOL> completed = end . date ( ) ) <EOL> self . deltas . append ( delta4 ) <EOL> self . delays . append ( e4 . start - <EOL> datetime . datetime . combine ( e4 . assigned , midnight ) ) <EOL> self . days_long . append ( e4 . completed - e4 . assigned ) <EOL> self . expnames = [ e . name for e in Experiment . objects . all ( ) ] <EOL> def test_multiple_query_compilation ( self ) : <EOL> queryset = Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) + datetime . timedelta ( hours = <NUM_LIT:1> ) ) <EOL> q1 = str ( queryset . query ) <EOL> q2 = str ( queryset . query ) <EOL> self . assertEqual ( q1 , q2 ) <EOL> def test_query_clone ( self ) : <EOL> qs = Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) + datetime . timedelta ( hours = <NUM_LIT:1> ) ) <EOL> qs2 = qs . all ( ) <EOL> list ( qs ) <EOL> list ( qs2 ) <EOL> def test_delta_add ( self ) : <EOL> for i in range ( len ( self . deltas ) ) : <EOL> delta = self . deltas [ i ] <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) + delta ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i ] ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( end__lte = F ( '<STR_LIT:start>' ) + delta ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i + <NUM_LIT:1> ] ) <EOL> def test_delta_subtract ( self ) : <EOL> for i in range ( len ( self . deltas ) ) : <EOL> delta = self . deltas [ i ] <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( start__gt = F ( '<STR_LIT:end>' ) - delta ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i ] ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( start__gte = F ( '<STR_LIT:end>' ) - delta ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i + <NUM_LIT:1> ] ) <EOL> def test_exclude ( self ) : <EOL> for i in range ( len ( self . deltas ) ) : <EOL> delta = self . deltas [ i ] <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . exclude ( end__lt = F ( '<STR_LIT:start>' ) + delta ) ] <EOL> self . assertEqual ( test_set , self . expnames [ i : ] ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . exclude ( end__lte = F ( '<STR_LIT:start>' ) + delta ) ] <EOL> self . assertEqual ( test_set , self . expnames [ i + <NUM_LIT:1> : ] ) <EOL> def test_date_comparison ( self ) : <EOL> for i in range ( len ( self . days_long ) ) : <EOL> days = self . days_long [ i ] <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( completed__lt = F ( '<STR_LIT>' ) + days ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i ] ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( completed__lte = F ( '<STR_LIT>' ) + days ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i + <NUM_LIT:1> ] ) <EOL> @ skipUnlessDBFeature ( "<STR_LIT>" ) <EOL> def test_mixed_comparisons1 ( self ) : <EOL> for i in range ( len ( self . delays ) ) : <EOL> delay = self . delays [ i ] <EOL> if not connection . features . supports_microsecond_precision : <EOL> delay = datetime . timedelta ( delay . days , delay . seconds ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( assigned__gt = F ( '<STR_LIT:start>' ) - delay ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i ] ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( assigned__gte = F ( '<STR_LIT:start>' ) - delay ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i + <NUM_LIT:1> ] ) <EOL> def test_mixed_comparisons2 ( self ) : <EOL> delays = [ datetime . timedelta ( delay . days ) for delay in self . delays ] <EOL> for i in range ( len ( delays ) ) : <EOL> delay = delays [ i ] <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( start__lt = F ( '<STR_LIT>' ) + delay ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i ] ) <EOL> test_set = [ e . name for e in <EOL> Experiment . objects . filter ( start__lte = F ( '<STR_LIT>' ) + delay + <EOL> datetime . timedelta ( <NUM_LIT:1> ) ) ] <EOL> self . assertEqual ( test_set , self . expnames [ : i + <NUM_LIT:1> ] ) <EOL> def test_delta_update ( self ) : <EOL> for i in range ( len ( self . deltas ) ) : <EOL> delta = self . deltas [ i ] <EOL> exps = Experiment . objects . all ( ) <EOL> expected_durations = [ e . duration ( ) for e in exps ] <EOL> expected_starts = [ e . start + delta for e in exps ] <EOL> expected_ends = [ e . end + delta for e in exps ] <EOL> Experiment . objects . update ( start = F ( '<STR_LIT:start>' ) + delta , end = F ( '<STR_LIT:end>' ) + delta ) <EOL> exps = Experiment . objects . all ( ) <EOL> new_starts = [ e . start for e in exps ] <EOL> new_ends = [ e . end for e in exps ] <EOL> new_durations = [ e . duration ( ) for e in exps ] <EOL> self . assertEqual ( expected_starts , new_starts ) <EOL> self . assertEqual ( expected_ends , new_ends ) <EOL> self . assertEqual ( expected_durations , new_durations ) <EOL> def test_delta_invalid_op_mult ( self ) : <EOL> raised = False <EOL> try : <EOL> r = repr ( Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) * self . deltas [ <NUM_LIT:0> ] ) ) <EOL> except TypeError : <EOL> raised = True <EOL> self . assertTrue ( raised , "<STR_LIT>" ) <EOL> def test_delta_invalid_op_div ( self ) : <EOL> raised = False <EOL> try : <EOL> r = repr ( Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) / self . deltas [ <NUM_LIT:0> ] ) ) <EOL> except TypeError : <EOL> raised = True <EOL> self . assertTrue ( raised , "<STR_LIT>" ) <EOL> def test_delta_invalid_op_mod ( self ) : <EOL> raised = False <EOL> try : <EOL> r = repr ( Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) % self . deltas [ <NUM_LIT:0> ] ) ) <EOL> except TypeError : <EOL> raised = True <EOL> self . assertTrue ( raised , "<STR_LIT>" ) <EOL> def test_delta_invalid_op_and ( self ) : <EOL> raised = False <EOL> try : <EOL> r = repr ( Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) . bitand ( self . deltas [ <NUM_LIT:0> ] ) ) ) <EOL> except TypeError : <EOL> raised = True <EOL> self . assertTrue ( raised , "<STR_LIT>" ) <EOL> def test_delta_invalid_op_or ( self ) : <EOL> raised = False <EOL> try : <EOL> r = repr ( Experiment . objects . filter ( end__lt = F ( '<STR_LIT:start>' ) . bitor ( self . deltas [ <NUM_LIT:0> ] ) ) ) <EOL> except TypeError : <EOL> raised = True <EOL> self . assertTrue ( raised , "<STR_LIT>" ) </s>
