def test_float_assignment() -> None:
    basic = Basic()

    run_test(basic, "let a1 = 0.7", "test_positive_float_assignment",
             LangNumber, None, 0.7)
    run_test(basic, "let a2 = -0.7", "test_negative_float_assignment",
             LangNumber, None, -0.7)
Ejemplo n.º 2
0
    def POST(self):
        try:
            token = Basic().get_access_token()
            print(token)
            webData = web.data()
            recMsg = receive.parse_xml(webData)
            if isinstance(recMsg, receive.Msg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                if recMsg.MsgType == 'text':
                    content = "欢迎光临!"
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                if recMsg.MsgType == 'image':
                    mediaId = recMsg.MediaId
                    replyImageMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyImageMsg.send()
                else:
                    return reply.Msg().send()

            else:
                print("暂且不处理")
                return reply.Msg().send()
        except  Exception as Argment:
            print(Argment)
            return Argment
Ejemplo n.º 3
0
def test_division_by_zero() -> None:
    basic = Basic()

    run_test(basic, " let _ = 42/0", "test_integer division by zero", None,
             RTError)
    run_test(basic, " let _ = 42.5/0", "test_float division by zero", None,
             RTError)
Ejemplo n.º 4
0
	def __init__(self):
		self.robot = Robot()
		self.basic = Basic()
		self.material = Material()
		self.dao  = Dao()
		self.dao.connect()
		self.spider = Spider()
Ejemplo n.º 5
0
def test_integer_equals() -> None:
    basic = Basic()

    run_test(
        basic,
        " let _ = 4 != +2",
        "test_positive_integer_equals",
        LangBool,
        None,
        4 != 2,
    )
    run_test(
        basic,
        " let _ = 4 != 4",
        "test_positive_integer_not_equals",
        LangBool,
        None,
        (4 != 4),
    )
    run_test(
        basic,
        " let _ = -4 != -2",
        "test_negative_integer_not_equals",
        LangBool,
        None,
        (-4 != -2),
    )
    run_test(
        basic,
        " let _ = 4 != -2",
        "test_mixed_integer_not_equals",
        LangBool,
        None,
        (4 != -2),
    )
def test_parentheses() -> None:
    basic = Basic()

    run_test(
        basic, " let _ = (4 + 2)", "test_single_parentheses", LangNumber, None, (4 + 2)
    )
    run_test(
        basic, " let _ = (4) + 2", "test_single_parentheses", LangNumber, None, (4) + 2
    )
    run_test(
        basic,
        " let _ = ((4 + 2) + 6)",
        "test_double_parentheses",
        LangNumber,
        None,
        ((4 + 2) + 6),
    )
    run_test(
        basic,
        " let _ = -((4 + 2) + 6)",
        "test_double_parentheses_negation",
        LangNumber,
        None,
        -((4 + 2) + 6),
    )
Ejemplo n.º 7
0
def test_mixed_logic_operator() -> None:
    basic = Basic()

    for name, operator in OPERATORS.items():
        run_test(
            basic,
            " let _ = 4.5 " + operator + " 5",
            "test_positive_mixed_" + name,
            LangBool,
            None,
            (eval("4.5 " + operator + " 5")),
        )
        run_test(
            basic,
            " let _ = -4.5 " + operator + " -2",
            "test_negative_mixed_" + name,
            LangBool,
            None,
            (eval("-4.5 " + operator + " -2")),
        )
        run_test(
            basic,
            " let _ = -4.0 " + operator + " -4",
            "test_negative_mixed_" + name,
            LangBool,
            None,
            (eval("-4.0 " + operator + " -4")),
        )
Ejemplo n.º 8
0
def test_fib_naive() -> None:
    basic = Basic()
    run_test(
        basic,
        """
        let fib =
            let fib_pom a b n =
                if n == 0 then
                    a
                else
                    fib_pom b (a+b) (n-1)
            in
                fib_pom 0 1
        """,
        "test_fib_part1",
        LangFunction,
        None,
    )
    for i in range(42):
        run_test(
            basic,
            f"let _ = fib {i}",
            f"test_fib_in_part{i + 1}",
            LangNumber,
            None,
            fib(i),
        )
Ejemplo n.º 9
0
def test_wrong_logic_operator() -> None:
    basic = Basic()
    for name, operator in OPERATORS.items():
        run_test(
            basic,
            " let _ = 42" + operator,
            "test_wrong_order_" + name,
            None,
            InvalidSyntaxError,
        )
        run_test(
            basic,
            " let _ = 42.5" + operator,
            "test_wrong_order_" + name + "_float",
            None,
            InvalidSyntaxError,
        )
        run_test(
            basic,
            " let _ = " + operator + "42",
            "test_wrong_order_" + name,
            None,
            InvalidSyntaxError,
        )
        run_test(
            basic,
            " let _ = " + operator + "42.5",
            "test_wrong_order_" + name + "_float",
            None,
            InvalidSyntaxError,
        )
Ejemplo n.º 10
0
 def batch_user_info(self, list):
     accessToken = Basic().get_access_token()
     postUrl = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=%s" % accessToken
     print list
     urlResp = urllib.urlopen(postUrl, list)
     urlResp = json.loads(urlResp.read())
     return urlResp
Ejemplo n.º 11
0
 def user_list(self, next_openid):
     accessToken = Basic().get_access_token()
     postUrl = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s" % (
         accessToken, next_openid)
     urlResp = urllib.urlopen(postUrl)
     urlResp = json.loads(urlResp.read())
     return urlResp
Ejemplo n.º 12
0
def test_tuple_correct_syntax() -> None:
    basic = Basic()

    run_test(basic, "let _ = 1", "test_tuple_valid_syntax1", LangNumber, None)
    run_test(basic, "let _ = 1, 2", "test_tuple_valid_syntax2", LangTuple, None)
    run_test(basic, "let _ = 1, 2, 3", "test_tuple_valid_syntax3", LangTuple, None)
    run_test(basic, "let _ = (1, 2)", "test_tuple_valid_syntax4", LangTuple, None)
def test_integer_arithmetic_operator() -> None:
    basic = Basic()

    for name, operator in OPERATORS.items():
        run_test(
            basic,
            " let _ = 4 " + operator + " +2",
            "test_positive_integer" + name,
            LangNumber,
            None,
            (eval("4 " + py_op(operator) + " +2")),
        )
        run_test(
            basic,
            " let _ = -4 " + operator + " -2",
            "test_positive_integer_" + name,
            LangNumber,
            None,
            (eval("-4 " + py_op(operator) + " -2")),
        )
        run_test(
            basic,
            " let _ = 4 " + operator + " -2",
            "test_negative_" + name,
            LangNumber,
            None,
            (eval("4 " + py_op(operator) + " -2")),
        )
def test_mixed_arithmetic_operator() -> None:
    basic = Basic()

    for name, operator in OPERATORS.items():
        run_test(
            basic,
            " let _ = 4.5 " + operator + " +5",
            "test_positive_mixed_" + name,
            LangNumber,
            None,
            (eval("4.5 " + py_op(operator) + " +5")),
        )
        run_test(
            basic,
            " let _ = -4.5 " + operator + " -2",
            "test_negative_mixed_" + name,
            LangNumber,
            None,
            (eval("-4.5 " + py_op(operator) + " -2")),
        )
        run_test(
            basic,
            " let _ = -4.0 " + operator + " -4",
            "test_negative_mixed_" + name,
            LangNumber,
            None,
            (eval("-4.0 " + py_op(operator) + " -4")),
        )
Ejemplo n.º 15
0
def test_if() -> None:
    basic = Basic()

    run_test(
        basic,
        " let _ = if false then 1 else 2",
        "test_if_just_else1",
        LangNumber,
        None,
        2,
    )
    run_test(
        basic,
        " let _ = if false then 1 elif true then 2 else 3",
        "test_if_elif_1",
        LangNumber,
        None,
        2,
    )
    run_test(
        basic,
        " let _ = if false then 1 elif false then 2 else 3",
        "test_if_elif_2",
        LangNumber,
        None,
        3,
    )
    run_test(
        basic,
        "let _ = if false then 1 elif false then 2 elif true then 42 else 69",
        "test_if_multi_elif_1",
        LangNumber,
        None,
        42,
    )
    run_test(
        basic,
        "let _ = if false then 1 elif false then 2 elif false then 42 else 69",
        "test_if_multi_elif_2",
        LangNumber,
        None,
        69,
    )
    run_test(
        basic,
        "let _ = if false then 1 elif false then 2 else if true then 42 else 69",
        "test_if_nested_if_1",
        LangNumber,
        None,
        42,
    )
    run_test(
        basic,
        "let _ = if false then 1 elif false then 2 else if false then 42 else 69",
        "test_if_nested_if_2",
        LangNumber,
        None,
        69,
    )
Ejemplo n.º 16
0
    def POST(self):
        try:
            webData = web.data()
            print "Handle Post webdata is ", webData  # 后台打印日志
            recMsg = receive.parse_xml(webData)  # 解析webData
            if isinstance(recMsg, receive.Msg):  # 若recMsg为消息类
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                print recMsg.MsgType
                if recMsg.MsgType == 'text':
                    content = recMsg.Content
                    picPath = "/home/pi/media/%s.jpg" % content
                    #print "content is %s"%content
                    #print "picPath is %s"%picPath
                    # 若名为content的图片存在,且大小小于2M,则上传到临时素材,获得mediaId
                    if os.path.exists(
                            picPath) and os.path.getsize(picPath) < 2097152:
                        print "Sending picture %s.jpg, size: %sB" % (
                            content, os.path.getsize(picPath))
                        myMedia = Media()
                        accessToken = Basic().get_access_token()
                        mediaType = "image"
                        mediaId = myMedia.upload(accessToken, picPath,
                                                 mediaType)
                        # 发送图片
                        replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                        return replyMsg.send()
                    else:
                        print "%s not valid" % picPath
                        return "success"
                else:
                    return "success"

            elif isinstance(recMsg, receive.Evt):  # 若recMsg为事件类
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                print recMsg.Event
                # 若事件类型为订阅,发送使用提示
                if recMsg.Event == 'subscribe':
                    #print "Sending qrcode..."
                    # 获取accessToken,上传临时素材
                    #myMedia = Media()
                    #accessToken = Basic().get_access_token()
                    #filePath = "/home/pi/media/qrcode.png"
                    #mediaType = "image"
                    #mediaId = myMedia.upload(accessToken, filePath, mediaType)
                    # 发送二维码
                    # replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    # return replyMsg.send()
                    content = "共享拍立得:请发送图片码获取图片"
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                else:
                    return "success"
            else:
                print "No action"
                return "success"
        except Exception, Argument:
            return Argument
Ejemplo n.º 17
0
	def setEnvironment(self, SCENARIO):
		if SCENARIO == 'Basic':
			self.Parser = csim.Parser("Basic")

		obs = self.Observe()

		if SCENARIO == 'Basic':
			self.Scenario = Basic(obs)
Ejemplo n.º 18
0
def main():
    myMedia = Media()
    accessToken = Basic().get_access_token()
    # filePath = "C:/Users/Hyman/Downloads/20170618232847.png"  # 请安实际填写
    # mediaType = "image"
    # myMedia.uplaod(accessToken, filePath, mediaType)
    mediaId = "Z2vMPZZ50kPwrJdwMX5bvcnj0cyx6hoySUhsBSB03iHWR6RU0Lk9EMMiojF3NtLA"
    myMedia.get(accessToken, mediaId)
Ejemplo n.º 19
0
def picture_url(picture_name):
    myMedia = Media()
    accessToken = Basic().get_access_token()
    filePath = picture_name
    mediaType = "image"
    murlResp = Media.uplaod(accessToken, filePath, mediaType)
    #print(murlResp)
    return murlResp
Ejemplo n.º 20
0
    def get(self):
        file_id = request.args.get('id')
        if not file_id:
            file_id = 'hazrat_kth_se'
        basic = Basic(file_id)
        channels = basic.get_channel_names()
        print('BASIC Flask channels :', channels)

        return channels
Ejemplo n.º 21
0
def test_pass_to_function() -> None:
    basic = Basic()

    run_test(basic, "let test list = []", "test_lists_in_functions1",
             LangFunction, None)
    run_test(basic, "test []", "test_lists_in_functions2", LangVariantType,
             None)
    run_test(basic, "test ([])", "test_lists_in_functions2", LangVariantType,
             None)
Ejemplo n.º 22
0
 def batch_get(self, mediaType, offset=0, count=20):
     accessToken = Basic().getAccessToken()
     postUrl = ("https://api.weixin.qq.com/cgi-bin/material"
                "/batchget_material?access_token=%s" % accessToken)
     postData = ("{ \"type\": \"%s\", \"offset\": %d, \"count\": %d }" %
                 (mediaType, offset, count))
     urlResp = urllib2.urlopen(postUrl, postData)
     jsonDict = json.loads(urlResp.read())
     return jsonDict
Ejemplo n.º 23
0
def get_media_ID(path):
    img_url = 'https://api.weixin.qq.com/cgi-bin/media/upload'
    payload_img = {
        'access_token': Basic().get_access_token(),
        'type': 'image'
    }
    data = {'media': open(path, 'rb')}
    r = requests.post(url=img_url, params=payload_img, files=data)
    dict = r.json()
    return dict['media_id']
Ejemplo n.º 24
0
def main(file_name: str) -> None:
    with open(file_name, "r") as f:
        code = f.read()
    basic = Basic()
    try:
        results = basic.run(code, file_name)
        for result in results:
            print(result)
    except Error as err:
        print_error(err)
Ejemplo n.º 25
0
def main(debug: bool = False) -> None:
    basic = Basic()
    while True:
        text = input("basic > ")
        try:
            results = basic.run(text, "<stdin>", True, debug)
            for result in results:
                print(result)
        except Error as err:
            print_error(err)
Ejemplo n.º 26
0
def test_ack() -> None:
    basic = Basic()
    run_test(
        basic,
        "let add x y = x + y",
        "test_partial_part0",
        LangFunction,
        None,
    )
    run_test(
        basic,
        "let inc = add 1",
        "test_partial_part1",
        LangFunction,
        None,
    )

    for i in range(10):
        for j in range(10):
            run_test(
                basic,
                f"let _ = add {i} {j}",
                f"test_partials_part2.{i}.{j}",
                LangNumber,
                None,
                add(i, j),
            )
    for i in range(21):
        run_test(
            basic,
            f"let _ = inc {i}",
            f"test_partials_part3.{i}",
            LangNumber,
            None,
            inc(i),
        )
    for i in range(10):
        for j in range(10):
            run_test(
                basic,
                f"let _ = add {i} {j}",
                f"test_partials_part4.{i}.{j}",
                LangNumber,
                None,
                add(i, j),
            )
    for i in range(21):
        run_test(
            basic,
            f"let _ = inc {i}",
            f"test_partials_part5.{i}",
            LangNumber,
            None,
            inc(i),
        )
Ejemplo n.º 27
0
def test_negation() -> None:
    basic = Basic()

    run_test(basic, " let _ = -42", "test_single_negation", LangNumber, None,
             -42)
    run_test(basic, " let _ = --42", "test_double_negation", LangNumber, None,
             42)
    run_test(basic, " let _ = -42.5", "test_single_negation_float", LangNumber,
             None, -42.5)
    run_test(basic, " let _ = --42.5", "test_double_negation_float",
             LangNumber, None, 42.5)
Ejemplo n.º 28
0
def test_list_correct_syntax() -> None:
    basic = Basic()

    run_test(basic, "let _ = []", "test_list_valid_syntax1", LangVariantType,
             None)
    run_test(basic, "let _ = [1,2,3]", "test_list_valid_syntax2",
             LangVariantType, None)
    run_test(basic, "let _ = [1]", "test_list_valid_syntax3", LangVariantType,
             None)
    run_test(basic, "let _ = [1,]", "test_list_valid_syntax4", LangVariantType,
             None)
Ejemplo n.º 29
0
def test_list_invalid_syntax() -> None:
    basic = Basic()

    run_test(basic, "let _ = ][", "test_list_invalid_syntax1", None,
             InvalidSyntaxError)
    run_test(basic, "let _ = [1 2]", "test_list_invalid_syntax2", None,
             InvalidSyntaxError)
    run_test(basic, "let _ = [1, 2,,]", "test_list_invalid_syntax3", None,
             InvalidSyntaxError)
    run_test(basic, "let _ = [,]", "test_list_valid_syntax4", None,
             InvalidSyntaxError)
Ejemplo n.º 30
0
def test_tuple_invalid_syntax() -> None:
    basic = Basic()

    run_test(basic, "let _ = ,", "test_tuple_invalid_syntax1", None, InvalidSyntaxError)
    run_test(
        basic, "let _ = ,1", "test_tuple_invalid_syntax2", None, InvalidSyntaxError
    )
    run_test(
        basic, "let _ = 1,,1", "test_tuple_invalid_syntax3", None, InvalidSyntaxError
    )
    run_test(basic, "let _ = 1,,", "test_tuple_valid_syntax4", None, InvalidSyntaxError)