forked from chrysn/aiocoap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_commandline.py
42 lines (32 loc) · 1.58 KB
/
test_commandline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This file is part of the Python aiocoap library project.
#
# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>,
# 2013-2014 Christian Amsüss <[email protected]>
#
# aiocoap is free software, this file is published under the MIT license as
# described in the accompanying LICENSE file.
"""This tests launch the command line utility aiocoap-client in a sub-process.
The aiocoap-proxy utility is tested in test_proxy inside this process as
orchestration of success reporting is not that easy with a daemon process;
aiocoap-rd might need to get tested in a similar way to -proxy."""
import subprocess
import asyncio
import aiocoap
from .test_server import WithTestServer, no_warnings
from .common import PYTHON_PREFIX
from . import test_server
AIOCOAP_CLIENT = PYTHON_PREFIX + ['./aiocoap-client']
class TestCommandlineClient(WithTestServer):
@no_warnings
def test_help(self):
helptext = subprocess.check_output(AIOCOAP_CLIENT + ['--help'])
self.assertTrue(helptext.startswith(b'usage: aiocoap-client '))
@no_warnings
def test_get(self):
loop = asyncio.get_event_loop()
loop.run_until_complete(loop.run_in_executor(None, self._test_get))
def _test_get(self):
empty_default = subprocess.check_output(AIOCOAP_CLIENT + ['coap://' + self.servernetloc + '/empty'])
self.assertEqual(empty_default, b'')
empty_json = subprocess.check_output(AIOCOAP_CLIENT + ['coap://' + self.servernetloc + '/empty', '--accept', 'application/json', '--quiet'])
self.assertEqual(empty_json, b'{}')