示例#1
0
def test_foo_status_code(monkeypatch):
    def getmock(*args, **kwargs):
        return MockResponse()

    monkeypatch.setattr(requests, 'get', getmock)

    with pytest.raises(RuntimeError):
        res = main.foo('https://www.google.com')
示例#2
0
    def do_GET(self):
        if "query" in self.path:
            # If URI contains URLToTriggerGetRequestHandler, execute the python script that corresponds to it and get that data
            # whatever we send to "respond" as an argument will be sent back to client
            parsed = urlparse(self.path)
            params = parse_qs(parsed.query)
            print("VID: ", params["video"])
            print("Query: ", params["query"])
            content = main.foo(5)

            self.respond(
                content
            )  # we can retrieve response within this scope and then pass info to self.respond
        else:
            if self.path == "/":
                self.path = "/index.html"
            try:
                sendReply = False
                if self.path.endswith(".html"):
                    mimetype = 'text/html'
                    sendReply = True
                if self.path.endswith(".jpg"):
                    mimetype = 'image/jpg'
                    sendReply = True
                if self.path.endswith(".png"):
                    mimetype = 'image/png'
                    sendReply = True
                if self.path.endswith(".gif"):
                    mimetype = 'image/gif'
                    sendReply = True
                if self.path.endswith(".js"):
                    mimetype = 'application/javascript'
                    sendReply = True
                if self.path.endswith(".css"):
                    mimetype = 'text/css'
                    sendReply = True

                if sendReply == True:
                    #Open the static file requested and send it
                    f = open(web_dir + self.path)
                    self.send_response(200)
                    self.send_header('Content-type', mimetype)
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()

            except IOError:
                self.send_error(404, 'File Not Found: %s' % self.path)

        def do_POST(self):
            if "query" in self.path:
                return
示例#3
0
print(add(1, 2))
print(add(1, 2, 3))
print(add(1, 3, 5, 7, 9))
print('-' * 20, '用模块管理函数', '-' * 20)


def foo():
    print('hello, world!')


def foo():
    print('goodbye, world!')


# 下面的代码会输出什么呢? #goodbye, world!
foo()
from main import foo

# 输出main-hello, world!

foo()
from test import foo

# 输出test-goodbye, world!
foo()
import main as m1
import test as m2

# main,hello, world!
m1.foo()
# test,goodbye, world!
def test_foo():
    assert foo() == "foo"
示例#5
0
from main import foo

assert foo() == 'bar'
示例#6
0
def test_hello():
    s = foo("im a test")
    assert s == "im a test"
示例#7
0
文件: test.py 项目: ds2643/mutpy
def test_foo():
    assert m.foo() == 1