summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/utils.py
diff options
context:
space:
mode:
authorManel Caro <mcaro@iseebcn.com>2020-07-31 02:07:37 +0200
committerManel Caro <mcaro@iseebcn.com>2020-07-31 02:07:37 +0200
commitd46bce422fd03cd57d1ba336361da17d6efb48db (patch)
treee5ec7aa1ee5d53a655ce121a7c2ddd95888fc989 /test-cli/test/helpers/utils.py
parent907b96801230e04d02575a3732a73e452089637b (diff)
downloadboard-d46bce422fd03cd57d1ba336361da17d6efb48db.zip
board-d46bce422fd03cd57d1ba336361da17d6efb48db.tar.gz
board-d46bce422fd03cd57d1ba336361da17d6efb48db.tar.bz2
TEST restructure
Diffstat (limited to 'test-cli/test/helpers/utils.py')
-rw-r--r--test-cli/test/helpers/utils.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/test-cli/test/helpers/utils.py b/test-cli/test/helpers/utils.py
new file mode 100644
index 0000000..8d2c27b
--- /dev/null
+++ b/test-cli/test/helpers/utils.py
@@ -0,0 +1,68 @@
+import json
+import socket
+import os
+import scanf
+
+def save_json_to_disk(filePath, description, mime, json_data, result):
+ with open(filePath, 'w') as outfile:
+ json.dump(json_data, outfile, indent=4)
+ outfile.close()
+ result.append(
+ {
+ "description": description,
+ "filepath": filePath,
+ "mimetype": mime
+ }
+ )
+
+def save_file_to_disk(filePath, description, mime, data, result):
+ with open(filePath, 'w') as outfile:
+ outfile.write(data)
+ outfile.close()
+ result.append(
+ {
+ "description": description,
+ "filepath": filePath,
+ "mimetype": mime
+ }
+ )
+
+def save_result (filePath, description, mime, result):
+ result.append(
+ {
+ "description": description,
+ "filepath": filePath,
+ "mimetype": mime
+ }
+ )
+
+
+def str2bool(v):
+ return v.lower() in ("yes", "true", "t", "1")
+
+def station2Port(base):
+ Name = socket.gethostname()
+ res = scanf.scanf("Station%d", Name)
+ if res[0]:
+ NmBase = int(base)
+ res = int(res[0])
+ return str(NmBase + res)
+ return base
+
+
+def sys_read(sysnode):
+ try:
+ f = open(sysnode, "r")
+ data = f.readline()
+ f.close()
+ except IOError as Error:
+ return False, '{}'.format(Error.errno)
+ return True, data
+
+def removefileIfExist(fname):
+ if os.path.exists(fname):
+ try:
+ os.remove(fname)
+ except OSError as error:
+ return False, str(error)
+ return True, ''