summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-05-29 19:41:02 +0300
committerLars Wirzenius <liw@liw.fi>2021-05-29 19:41:02 +0300
commit8466e748a92eb6898156b5ac0dd03dce5c389a1d (patch)
tree3a357edf7455c8cf0412ecc136a4985fe59290e1
parentf035ecdb2e03a09f629a68ee79b3f0f5fb97f692 (diff)
downloadoso-work-sample-8466e748a92eb6898156b5ac0dd03dce5c389a1d.tar.gz
feat: dummy server that always return result of 0
Sponsored-by: author
-rw-r--r--README.md8
-rwxr-xr-xcheck3
-rwxr-xr-xmax-client.py3
-rw-r--r--oso.py24
-rw-r--r--oso.yaml3
-rwxr-xr-xserver.py12
6 files changed, 42 insertions, 11 deletions
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)