コード例 #1
0
def sa_profile(request):
    dir_ = tempfile.mkdtemp(prefix='iottalkpy')
    dir_ = os.path.abspath(dir_)

    if request.param == ('sa', 'str'):
        content = '\n'.join(
            ["idf_list = ['Dummy_Sensor']", "odf_list = ['Dummy_Control']"])
    elif request.param == (
            'sa',
            'tuple',
            'len=2',
    ):
        content = '\n'.join([
            "idf_list = [('Dummy_Sensor', 'type',)]",
            "odf_list = [('Dummy_Control', 'type',)]"
        ])
    else:
        content = '\n'.join(["idf_list = [1, 2, 3,]", "odf_list = [10,]"])

    with tempfile.NamedTemporaryFile(suffix='.py', dir=dir_,
                                     delete=False) as f:
        f.write(content.encode())
    yield load_module(f.name)

    shutil.rmtree(dir_)
コード例 #2
0
def test_load_module(dai_path):
    m = load_module(dai_path)
    assert m
    assert m.__dict__
    assert m.__dict__['api_url'] == 'http://localhost:9992'
    assert m.__dict__['device_module'] == 'Dummy_Device'
    assert m.__dict__['idf_list'] == ['Dummy_Sensor']
    assert m.__dict__['push_interval'] == 10
    assert m.__dict__['interval'] == {'Dummy_Sensor': 1}
コード例 #3
0
def test_load_module_nonexists(dai_path_nonexists):
    with pytest.raises(Exception):
        load_module(dai_path_nonexists)
コード例 #4
0
from flask import Flask, request, abort, render_template, jsonify
from iottalkpy import dai

app = Flask(__name__)

@app.route("/", methods=['GET'])
def home():
	return render_template('index.html')
	
@app.route('/api/test')
def test_page():
	f_read = open('data.txt', 'r')
	data = '1'
	while True:
		data = f_read.read()
		if data:
			break
	f_read.close()
	return data

if __name__ == "__main__":
	sa = dai.module_to_sa(dai.load_module('ida.py'))
	sa.start()
	app.run(host='0.0.0.0', port=80)
	sa.terminate()