Skip to content

Commit ac1cf7b

Browse files
authored
Fix for input data bug (#5)
* Bug in read_input * Add test for input data * Empty input test
1 parent f513e14 commit ac1cf7b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pyfaasm/pyfaasm/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def read_input(input_len):
8383
_init_host_interface()
8484
input_len = int(input_len)
8585
buff = ctypes.create_string_buffer(input_len)
86-
return _host_interface.__faasm_read_input(buff, input_len)
86+
_host_interface.__faasm_read_input(buff, input_len)
87+
88+
return buff.value
8789

8890

8991
def write_output(output):

pyfaasm/test/test_inputs.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
import json
3+
from pyfaasm.core import (
4+
get_input_len,
5+
read_input,
6+
set_emulator_message,
7+
)
8+
9+
10+
class TestInputs(unittest.TestCase):
11+
def test_input_data(self):
12+
expected = "blah blah foo bar"
13+
msg = {"user": "foo", "function": "bar", "input_data": expected}
14+
15+
set_emulator_message(json.dumps(msg))
16+
17+
input_len = get_input_len()
18+
self.assertEqual(input_len, len(expected))
19+
20+
actual_bytes = read_input(input_len)
21+
actual = actual_bytes.decode("utf-8")
22+
23+
self.assertEqual(actual, expected)
24+
25+
def test_empty_input_data(self):
26+
msg = {"user": "foo", "function": "bar"}
27+
28+
set_emulator_message(json.dumps(msg))
29+
30+
input_len = get_input_len()
31+
self.assertEqual(input_len, 0)

0 commit comments

Comments
 (0)