From 8466e748a92eb6898156b5ac0dd03dce5c389a1d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 29 May 2021 19:41:02 +0300 Subject: feat: dummy server that always return result of 0 Sponsored-by: author --- README.md | 8 ++++++-- check | 3 ++- max-client.py | 3 ++- oso.py | 24 +++++++++++++++++++----- oso.yaml | 3 +-- server.py | 12 ++++++++++++ 6 files changed, 42 insertions(+), 11 deletions(-) create mode 100755 server.py diff --git a/README.md b/README.md index 6807dbd..eeb0156 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ computation. ~~~json { - "type": "one", + "type": "done", "result": 2 } ~~~ @@ -171,7 +171,7 @@ list of one. ~~~scenario given server -when I run client with list consisting of 1 +when I run max-client.py 1 then answer is 0 ~~~ @@ -184,6 +184,10 @@ classes: template: python bindings: - oso.yaml +- lib/daemon.yaml +- lib/runcmd.yaml functions: - oso.py +- lib/daemon.py +- lib/runcmd.py ... diff --git a/check b/check index c438751..182d952 100755 --- a/check +++ b/check @@ -1,12 +1,13 @@ #!/bin/bash set -euo pipefail +set -x subplot docgen README.md -o README.pdf subplot docgen README.md -o README.html subplot codegen README.md -o test.py rm -f test.log fail.tar.gz -python3 test.py --log test.log --save-on-failure test.log +python3 test.py --log test.log --save-on-failure fail.tar.gz echo OK diff --git a/max-client.py b/max-client.py index 818647e..d78db1a 100755 --- a/max-client.py +++ b/max-client.py @@ -100,6 +100,7 @@ if __name__ == "__main__": metavar="OP", type=str, choices=("max", "min"), + default="max", help="what operation to compute on the numbers? max or min", ) parser.add_argument( @@ -111,6 +112,6 @@ if __name__ == "__main__": ) args = parser.parse_args() - client = Client(args.address, log=True) + client = Client(args.address, log=False) answer = client.compute(args.numbers, op=args.compute) print(answer) diff --git a/oso.py b/oso.py index a57f8fc..2aaee76 100644 --- a/oso.py +++ b/oso.py @@ -1,13 +1,27 @@ +import os + + def start_server(ctx): - pass + # Declare Subplot library names. In the generated Python program, the + # libraries will be included and can just be used via names, but to placate + # automated checks that only see this file, get the names from globals() at + # runtime. + daemon_start_on_port = globals()["daemon_start_on_port"] + runcmd_helper_srcdir_path = globals()["runcmd_helper_srcdir_path"] + srcdir = globals()["srcdir"] + # This installs srcdir in $PATH so that we can run the client and server + # easily. + runcmd_helper_srcdir_path(ctx) -def stop_server(ctx): - pass + # Start server. + server = os.path.join(srcdir, "server.py") + daemon_start_on_port(ctx, path=server, args="", name="server", port=5000) -def run_client(ctx, items=None): - pass +def stop_server(ctx): + daemon_stop = globals()["daemon_stop"] + daemon_stop(ctx, name="server") def answer_is(ctx, index): diff --git a/oso.yaml b/oso.yaml index 29351c0..32d4651 100644 --- a/oso.yaml +++ b/oso.yaml @@ -1,7 +1,6 @@ - given: server function: start_server cleanup: stop_server -- when: I run client with list consisting of {items:text} - function: run_client + - then: answer is {index} function: answer_is diff --git a/server.py b/server.py new file mode 100755 index 0000000..369fa79 --- /dev/null +++ b/server.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import bottle + + +@bottle.post("/") +def root(): + bottle.response.content_type = "application/json" + return {"type": "done", "result": 0} + + +bottle.run(host="localhost", port=5000) -- cgit v1.2.1