def test_need_logcode(servlet, tmp_path):

    with pytest.raises(NotImplementedError):
        asyncio.run(
            client.main(8765, "localhost", 2,
                        log_file=tmp_path / "nobody.txt"))
    servlet.terminate()
def test_server_client(servlet, capsys, tmp_path):
    """
    this is not a typical way to write a data file, but is used here
    since the assignment tasks include writing a file so I did this test
    unconventionally
    """
    N = 5
    fn = tmp_path / "test.log"

    asyncio.run(client.main(8765, "localhost", N, log_file=fn))
    servlet.terminate()

    stdout, stderr = capsys.readouterr()
    fn.write_text(stdout.split("\n", 1)[1])

    dat = fio.load_data(fn)
    assert sorted(dat.keys()) == ["co2", "occupancy",
                                  "temperature"], "wrong keys"
The default behavior is to only access the computer itself by parameter "localhost"
so that no firewall edits are needed.

The port number is arbitrary, as long as the server and client are on the same port all is well.

Naturally, the server ws_server.py must be started before this client attempts to connect.
"""

import argparse
import asyncio

from sp_iotsim.client import main

if __name__ == "__main__":
    p = argparse.ArgumentParser(description="WebSocket client")
    p.add_argument("-l", "--log", help="file to log JSON data")
    p.add_argument("-host", help="Host address", default="localhost")
    p.add_argument("-port", help="network port", type=int, default=8765)
    p.add_argument(
        "-max_packets",
        help="shut down program after total packages received",
        type=int,
        default=100000,
    )
    P = p.parse_args()

    try:
        asyncio.run(main(P.port, P.host, P.max_packets, P.log))
    except KeyboardInterrupt:
        print(P.log)
def test_server(servlet):
    asyncio.run(client.main(8765, "localhost", 5))
    servlet.terminate()