@@ -2715,6 +2715,259 @@ def test_qb_std_union_object_02(self):
27152715 [inh_a_objs [13 ], inh_a_objs [17 ]], result
27162716 )
27172717
2718+ def test_qb_std_if_else_scalar_01a (self ):
2719+ from models .orm_qb import std
2720+
2721+ lhs = [1 , 2 , 3 ]
2722+ rhs = [4 , 5 , 6 ]
2723+
2724+ query = std .if_else (lhs , True , rhs )
2725+ result = self .client .query (query )
2726+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2727+
2728+ query = std .if_else (lhs , False , rhs )
2729+ result = self .client .query (query )
2730+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2731+
2732+ query = std .if_else (lhs , std .bool (True ), rhs )
2733+ result = self .client .query (query )
2734+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2735+
2736+ query = std .if_else (lhs , std .bool (False ), rhs )
2737+ result = self .client .query (query )
2738+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2739+
2740+ def test_qb_std_if_else_scalar_01b (self ):
2741+ from models .orm_qb import std
2742+
2743+ lhs = [1 , 2 , 3 ]
2744+ rhs = [std .int64 (4 ), std .int64 (5 ), std .int64 (6 )]
2745+
2746+ query = std .if_else (lhs , True , rhs )
2747+ result = self .client .query (query )
2748+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2749+
2750+ query = std .if_else (lhs , False , rhs )
2751+ result = self .client .query (query )
2752+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2753+
2754+ query = std .if_else (lhs , std .bool (True ), rhs )
2755+ result = self .client .query (query )
2756+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2757+
2758+ query = std .if_else (lhs , std .bool (False ), rhs )
2759+ result = self .client .query (query )
2760+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2761+
2762+ def test_qb_std_if_else_scalar_01c (self ):
2763+ from models .orm_qb import std
2764+
2765+ lhs = [std .int64 (1 ), std .int64 (2 ), std .int64 (3 )]
2766+ rhs = [4 , 5 , 6 ]
2767+
2768+ query = std .if_else (lhs , True , rhs )
2769+ result = self .client .query (query )
2770+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2771+
2772+ query = std .if_else (lhs , False , rhs )
2773+ result = self .client .query (query )
2774+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2775+
2776+ query = std .if_else (lhs , std .bool (True ), rhs )
2777+ result = self .client .query (query )
2778+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2779+
2780+ query = std .if_else (lhs , std .bool (False ), rhs )
2781+ result = self .client .query (query )
2782+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2783+
2784+ def test_qb_std_if_else_scalar_01d (self ):
2785+ from models .orm_qb import std
2786+
2787+ lhs = [std .int64 (1 ), std .int64 (2 ), std .int64 (3 )]
2788+ rhs = [std .int64 (4 ), std .int64 (5 ), std .int64 (6 )]
2789+
2790+ query = std .if_else (lhs , True , rhs )
2791+ result = self .client .query (query )
2792+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2793+
2794+ query = std .if_else (lhs , False , rhs )
2795+ result = self .client .query (query )
2796+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2797+
2798+ query = std .if_else (lhs , std .bool (True ), rhs )
2799+ result = self .client .query (query )
2800+ self ._assertListEqualUnordered ([1 , 2 , 3 ], result )
2801+
2802+ query = std .if_else (lhs , std .bool (False ), rhs )
2803+ result = self .client .query (query )
2804+ self ._assertListEqualUnordered ([4 , 5 , 6 ], result )
2805+
2806+ def test_qb_std_if_else_scalar_02a (self ):
2807+ from models .orm_qb import std
2808+
2809+ lhs = [True , True , True ]
2810+ rhs = [False , False , False ]
2811+
2812+ query = std .if_else (lhs , True , rhs )
2813+ result = self .client .query (query )
2814+ self ._assertListEqualUnordered ([True , True , True ], result )
2815+
2816+ query = std .if_else (lhs , False , rhs )
2817+ result = self .client .query (query )
2818+ self ._assertListEqualUnordered ([False , False , False ], result )
2819+
2820+ query = std .if_else (lhs , std .bool (True ), rhs )
2821+ result = self .client .query (query )
2822+ self ._assertListEqualUnordered ([True , True , True ], result )
2823+
2824+ query = std .if_else (lhs , std .bool (False ), rhs )
2825+ result = self .client .query (query )
2826+ self ._assertListEqualUnordered ([False , False , False ], result )
2827+
2828+ def test_qb_std_if_else_scalar_02b (self ):
2829+ from models .orm_qb import std
2830+
2831+ lhs = [True , True , True ]
2832+ rhs = [std .bool (False ), std .bool (False ), std .bool (False )]
2833+
2834+ query = std .if_else (lhs , True , rhs )
2835+ result = self .client .query (query )
2836+ self ._assertListEqualUnordered ([True , True , True ], result )
2837+
2838+ query = std .if_else (lhs , False , rhs )
2839+ result = self .client .query (query )
2840+ self ._assertListEqualUnordered ([False , False , False ], result )
2841+
2842+ query = std .if_else (lhs , std .bool (True ), rhs )
2843+ result = self .client .query (query )
2844+ self ._assertListEqualUnordered ([True , True , True ], result )
2845+
2846+ query = std .if_else (lhs , std .bool (False ), rhs )
2847+ result = self .client .query (query )
2848+ self ._assertListEqualUnordered ([False , False , False ], result )
2849+
2850+ def test_qb_std_if_else_scalar_02c (self ):
2851+ from models .orm_qb import std
2852+
2853+ lhs = [std .bool (True ), std .bool (True ), std .bool (True )]
2854+ rhs = [False , False , False ]
2855+
2856+ query = std .if_else (lhs , True , rhs )
2857+ result = self .client .query (query )
2858+ self ._assertListEqualUnordered ([True , True , True ], result )
2859+
2860+ query = std .if_else (lhs , False , rhs )
2861+ result = self .client .query (query )
2862+ self ._assertListEqualUnordered ([False , False , False ], result )
2863+
2864+ query = std .if_else (lhs , std .bool (True ), rhs )
2865+ result = self .client .query (query )
2866+ self ._assertListEqualUnordered ([True , True , True ], result )
2867+
2868+ query = std .if_else (lhs , std .bool (False ), rhs )
2869+ result = self .client .query (query )
2870+ self ._assertListEqualUnordered ([False , False , False ], result )
2871+
2872+ def test_qb_std_if_else_scalar_02d (self ):
2873+ from models .orm_qb import std
2874+
2875+ lhs = [std .bool (True ), std .bool (True ), std .bool (True )]
2876+ rhs = [std .bool (False ), std .bool (False ), std .bool (False )]
2877+
2878+ query = std .if_else (lhs , True , rhs )
2879+ result = self .client .query (query )
2880+ self ._assertListEqualUnordered ([True , True , True ], result )
2881+
2882+ query = std .if_else (lhs , False , rhs )
2883+ result = self .client .query (query )
2884+ self ._assertListEqualUnordered ([False , False , False ], result )
2885+
2886+ query = std .if_else (lhs , std .bool (True ), rhs )
2887+ result = self .client .query (query )
2888+ self ._assertListEqualUnordered ([True , True , True ], result )
2889+
2890+ query = std .if_else (lhs , std .bool (False ), rhs )
2891+ result = self .client .query (query )
2892+ self ._assertListEqualUnordered ([False , False , False ], result )
2893+
2894+ def test_qb_std_if_else_object_01 (self ):
2895+ from models .orm_qb import default , std
2896+
2897+ inh_a_objs = {
2898+ obj .a : obj
2899+ for obj in self .client .query (default .Inh_A .select (a = True ))
2900+ }
2901+
2902+ query = std .if_else (default .Inh_ABC , True , default .Inh_AB_AC )
2903+ result = self .client .query (query )
2904+ self ._assertListEqualUnordered ([inh_a_objs [13 ]], result )
2905+
2906+ query = std .if_else (default .Inh_ABC , False , default .Inh_AB_AC )
2907+ result = self .client .query (query )
2908+ self ._assertListEqualUnordered ([inh_a_objs [17 ]], result )
2909+
2910+ query = std .if_else (default .Inh_ABC , std .bool (True ), default .Inh_AB_AC )
2911+ result = self .client .query (query )
2912+ self ._assertListEqualUnordered ([inh_a_objs [13 ]], result )
2913+
2914+ query = std .if_else (
2915+ default .Inh_ABC , std .bool (False ), default .Inh_AB_AC
2916+ )
2917+ result = self .client .query (query )
2918+ self ._assertListEqualUnordered ([inh_a_objs [17 ]], result )
2919+
2920+ def test_qb_std_if_else_object_02 (self ):
2921+ from models .orm_qb import default , std
2922+
2923+ query = default .Inh_A .select (
2924+ a = lambda x : std .if_else (x .a , x .a < 10 , x .a + 100 )
2925+ )
2926+ result = self .client .query (query )
2927+
2928+ self ._assertObjectsWithFields (
2929+ result ,
2930+ "a" ,
2931+ [
2932+ (
2933+ default .Inh_A ,
2934+ {
2935+ "a" : 1 ,
2936+ },
2937+ ),
2938+ (
2939+ default .Inh_AB ,
2940+ {
2941+ "a" : 4 ,
2942+ },
2943+ ),
2944+ (
2945+ default .Inh_AC ,
2946+ {
2947+ "a" : 7 ,
2948+ },
2949+ ),
2950+ (
2951+ default .Inh_ABC ,
2952+ {
2953+ "a" : 113 ,
2954+ },
2955+ ),
2956+ (
2957+ default .Inh_AB_AC ,
2958+ {
2959+ "a" : 117 ,
2960+ },
2961+ ),
2962+ (
2963+ default .Inh_AXA ,
2964+ {
2965+ "a" : 1101 ,
2966+ },
2967+ ),
2968+ ],
2969+ )
2970+
27182971
27192972class TestQueryBuilderModify (tb .ModelTestCase ):
27202973 """This test suite is for data manipulation using QB."""
0 commit comments