예제 #1
0
 def test_simple4(self):
     policy = (
         'edit.field_comparison(field_path="a", comparison_operator="eq", value=4)'
         '.((_enforce_comparison(result=True).ret) + '
         '(_enforce_comparison(result=False).test.ret))')
     program = (
         "dp0=edit(data=dp0, key='a', value=4)\n"
         "if general.field_comparison(data=dp0, field_path='a', comparison_operator='eq',"
         " value=4):\n"
         "    ret(data=dp0)\n"
         "else:\n"
         "    dp0=test(data=dp0);ret(data=dp0)\n")
     self.assertTrue(run_test(program, policy))
예제 #2
0
 def test_time2(self):
     policy = ('edit.in_time_window(lower_str="00:00", upper_str="23:30", '
               'weekday_list=["mon","tue","wed","thur","fri"])'
               '.((_enforce_comparison(result=True).double(key="a").ret) + '
               '(_enforce_comparison(result=False).test.ret))')
     program = (
         "dp0=edit(data=dp0, key='a', value=4)\n"
         "if time.in_time_window(data=dp0, lower_str='00:00', upper_str='23:30',"
         "weekday_list=['mon','tue','wed','thur','fri']):\n"
         "    dp0=double(data=dp0, key='a')\n"
         "    ret(data=dp0)\n"
         "else:\n"
         "    dp0=test(data=dp0);ret(data=dp0)\n")
     self.assertTrue(run_test(program, policy))
예제 #3
0
 def test_collection_policy3(self):
     policy0 = 'edit.add_to_collection*.collection_sum(value_key="a")'
     policy1 = 'edit.add_to_collection*.collection_sum(value_key="a")'
     policy2 = 'edit.add_to_collection*.collection_sum(value_key="a")'
     program = (
         "dp0 = edit(data=dp0, key='a', value=4)\n"
         "dp1 = edit(data=dp1, key='a', value=4)\n"
         "dp2 = edit(data=dp2, key='a', value=5)\n"
         "col=Collection()\n"
         "col.add_to_collection(data=dp0)\n"
         "col.add_to_collection(data=dp1)\n"
         "col.add_to_collection(data=dp2)\n"
         "res = general.collection_sum(collection=col, value_key='a')")
     self.assertTrue(run_test(program, policy0, policy1, policy2))
예제 #4
0
 def test_dependent6(self):
     policy0 = ('edit.field_comparison(field_path="a", '
                'comparison_operator="eq", value=4, username="******", name="1")'
                '.((_enforce_comparison(result=True).ret) + '
                '(_enforce_comparison(result=False).test.ret))')
     policy1 = (
         'edit._dependent_comparison(field_path="a", '
         'comparison_operator="eq", value=4, username="******", name="0")')
     program = (
         "dp0=edit(data=dp0, key='b', value=3)\n"
         "dp1=edit(data=dp1, key='a', value=3)\n"
         "general.field_comparison(data=dp0, field_path='a', comparison_operator='eq',"
         " value=4, dependent_dp=dp1)\n"
         "dp0=test(data=dp0);ret(data=dp0)\n")
     self.assertTrue(run_test(program, policy0, policy1))
예제 #5
0
    def test_collection_policy11(self):
        policy0 = 'edit.add_to_collection*.(collection_average + (double.collection_average)).ret'
        policy1 = 'edit.add_to_collection*.(collection_average + (double.collection_average)).ret'
        policy2 = 'edit.add_to_collection*.(collection_average + (double.collection_average)).ret'
        program = (
            "dp0 = edit(data=dp0, key='a', value=4)\n"
            "dp1 = edit(data=dp1, key='a', value=4)\n"
            "dp2 = edit(data=dp2, key='a', value=4)\n"
            "col=Collection()\n"
            "col.add_to_collection(data=dp0)\n"
            "col.add_to_collection(data=dp1)\n"
            "col.add_to_collection(data=dp2)\n"
            "res = general.collection_average(collection=col, value_key='a')\n"
            "col2 = col.for_each(double, key='a')\n"
            "res2 = general.collection_average(collection=col2, value_key='a')\n"
            "ret(data=res)\n"
            "ret(data=res2)\n")

        self.assertTrue(run_test(program, policy0, policy1, policy2))
예제 #6
0
 def test_not_eq_two(self):
     policy = 'test(a!=4, b=5.0)'
     program = "dp0=test(data=dp0, a=6, b=5)"
     self.assertTrue(run_test(program, policy))
예제 #7
0
 def test_simple_params_three(self):
     policy = 'test(a=4, b=5.0)'
     program = "dp0=test(data=dp0, a=4, b=\"q\")"
     self.assertFalse(run_test(program, policy))
예제 #8
0
 def test_no_policy_params(self):
     policy = 'test'
     program = "dp0=test(data=dp0, a=4, b=5)"
     self.assertTrue(run_test(program, policy))
예제 #9
0
 def test_union_star(self):
     policy = '1+test*'
     program = "dp0=test(data=dp0)"
     self.assertTrue(run_test(program, policy))
예제 #10
0
 def test_intersect_1_1_pass(self):
     policy = 'ret.(1&1)'
     program = "ret(data=dp0)"
     self.assertTrue(run_test(program, policy))
예제 #11
0
 def test_simple_error_four(self):
     policy = 'test'
     program = "dp0=test(data=dp0);dp0=test(data=dp0);ret(data=dp0)"
     self.assertFalse(run_test(program, policy))
예제 #12
0
 def test_inequality_6(self):
     policy = 'test(a > 5.8, b >= -0.8)'
     program = "test(data=dp0, a=4.99, b=0)"
     self.assertFalse(run_test(program, policy))
예제 #13
0
 def test_inequality_5(self):
     policy = 'test(a < 5.0, b >= -0.8)'
     program = "test(data=dp0, a=4.99, b=0)"
     self.assertTrue(run_test(program, policy))
예제 #14
0
 def test_inequality_3(self):
     policy = 'test(a <= 5, b >= 0)'
     program = "test(data=dp0, a=5, b=0)"
     self.assertTrue(run_test(program, policy))
예제 #15
0
 def test_simple_error(self):
     policy = 'test.ret'
     program = "ret(data=dp0)"
     self.assertFalse(run_test(program, policy))
예제 #16
0
 def test_set7(self):
     policy = 'test(a in {4, 5.0, 6}, ! b in {"a", "b", "C"})'
     program = "test(data=dp0, a=5, b='a')"
     self.assertFalse(run_test(program, policy))
예제 #17
0
 def test_scope(self):
     policy = 'transform'
     program = "test(data=dp0, a=5, b='a')"
     self.assertTrue(run_test(program, policy))
예제 #18
0
 def test_range3(self):
     policy = 'test(4 < a < 5.0, -0.8 <= b < 4.6)'
     program = "test(data=dp0, a=4.1, b=-0.8)"
     self.assertTrue(run_test(program, policy))
예제 #19
0
    def test_intersect_star_fail(self):
        # @TODO this should pass according to our rules. Need to investigate.

        policy = '1&test*'
        program = "dp0=test(data=dp0)"
        self.assertFalse(run_test(program, policy))
예제 #20
0
 def test_range4(self):
     policy = 'test(4 < a < 5.0, -0.8 <= b < 4.6)'
     program = "test(data=dp0, a=4, b=0)"
     self.assertFalse(run_test(program, policy))
예제 #21
0
 def test_intersect_1_0_fail(self):
     policy = 'ret.(1&0)'
     program = "ret(data=dp0)"
     self.assertFalse(run_test(program, policy))
예제 #22
0
 def test_range8(self):
     policy = 'test(4 <= a < 5, -17 < b <= 4.6)'
     program = "test(data=dp0, a=4, b=4.6)"
     self.assertTrue(run_test(program, policy))
예제 #23
0
 def test_simple(self):
     policy = 'test.ret'
     program = "dp0=test(data=dp0);ret(data=dp0)"
     res = run_test(program, policy)
     self.assertTrue(res)
예제 #24
0
 def test_range10(self):
     policy = 'test(4 <= a < 5, -17 < b <= 4.6)'
     program = "test(data=dp0, a=5, b=0)"
     self.assertFalse(run_test(program, policy))
예제 #25
0
 def test_simple_params_two(self):
     policy = 'test(a=4, b=5.0)'
     program = "dp0=test(data=dp0, a=4, b=5)"
     self.assertTrue(run_test(program, policy))
예제 #26
0
 def test_range12(self):
     policy = 'test(! 4 <= a < 5, -17 < b <= 4.6)'
     program = "test(data=dp0, a=3.9, b=-16.9)"
     self.assertTrue(run_test(program, policy))
예제 #27
0
 def test_not_eq(self):
     policy = 'test(a!=4, b=5.0)'
     program = "dp0=test(data=dp0, a=4, b=5)"
     self.assertFalse(run_test(program, policy))
예제 #28
0
 def test_range14(self):
     policy = 'test(4 <= a < 5, !-17 < b <= 4.6)'
     program = "test(data=dp0, a=4, b=-16.9)"
     self.assertFalse(run_test(program, policy))
예제 #29
0
 def test_int_neq(self):
     policy = 'test(a!=147, b!=-5)'
     program = "dp0=test(data=dp0, a=148, b=5)"
     self.assertTrue(run_test(program, policy))
예제 #30
0
 def test_set6(self):
     policy = 'test(! a in {4, 5, 6}, b in {"a", "b", "C"})'
     program = "test(data=dp0, a=3, b='a')"
     self.assertTrue(run_test(program, policy))