Repository: MilesEngineering/MsgTools (language: python)

Issue:
CPP Unit Tests Broken
Fresh clone and install into clean virtual environment (Python 3.8.5 on Mac Big Sur 11.3).  CPP unit tests fail per below.

Also note the unsafe loader warning for pyyaml.

============
```
$ make test
==> make /Users/someuser/Projects/MsgTools/ThirdParty 
make[1]: Nothing to be done for `test'.
==> make /Users/someuser/Projects/MsgTools/msgtools 
==> make /Users/someuser/Projects/MsgTools/msgtools/parser 
/bin/sh: line 0: cd: ../../../messages: No such file or directory
cd test && make
python3 TestCpp.py
TestCpp.py:16: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  self.msgDict = yaml.load(self.msgIDL)
F...
======================================================================
FAIL: test_accessors (__main__.TestCpp)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "TestCpp.py", line 228, in test_accessors
    self.assertEqual(expCount, obsCount)
AssertionError: 29 != 31

----------------------------------------------------------------------
Ran 4 tests in 0.038s

FAILED (failures=1)
make[3]: *** [testCpp] Error 1
make[2]: *** [test] Error 2
make[1]: *** [test] Error 2
make: *** [test] Error 2
```


Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index 0a319b0..e90a73e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,6 +11,7 @@ matrix:
     before_install:
       - sudo apt-get install python3 python3-pip
       - sudo pip3 install pyyaml
+      - sudo pip3 install numpy==1.8
     install:
       - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
       - echo yes | sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2"
diff --git a/MsgApp/Makefile b/MsgApp/Makefile
index 2193fd9..c29f9f5 100644
--- a/MsgApp/Makefile
+++ b/MsgApp/Makefile
@@ -2,8 +2,8 @@
 
 all::
 
-test::
-	cd test && make
+# test::
+# 	cd test && make
 
 include makefile.inc
 include $(MK_DIR)/subdir.mk
diff --git a/setup.py b/setup.py
index 9c0c7be..cd67936 100755
--- a/setup.py
+++ b/setup.py
@@ -67,7 +67,8 @@
         'pyyaml',
         'websockets',
         'janus',
-        'jinja2'
+        'jinja2',
+        'numpy==1.18'
     ],
     extras_require={
         'gui':  ["pyqtgraph", "pyqt5", 'qscintilla'],


Test patch:
diff --git a/msgtools/parser/test/TestCpp.py b/msgtools/parser/test/TestCpp.py
index 5109ccc..6975e48 100755
--- a/msgtools/parser/test/TestCpp.py
+++ b/msgtools/parser/test/TestCpp.py
@@ -1,3 +1,4 @@
+
 #!/usr/bin/env python3
 import unittest
 import yaml
@@ -13,7 +14,7 @@ def setUp(self):
         self.maxDiff = None
         with open("messages/TestCase1.yaml", 'r') as inputFile:
             self.msgIDL = inputFile.read()
-        self.msgDict = yaml.load(self.msgIDL)
+        self.msgDict = yaml.load(self.msgIDL, Loader=yaml.SafeLoader)
         PatchStructs(self.msgDict)
 
     def test_accessors(self):
@@ -218,10 +219,70 @@ def test_accessors(self):
 """)
         expected.append("""\
 /*  , (0 to 255)*/
+void CopyInFieldC(const uint8_t* in, int len)
+{
+    int count = ((len < 5) ? len : 5);
+    for(int i=0; i<count; i++)
+    {
+        SetFieldC(in[i], i);
+    }
+}
+/*  , (0 to 255)*/
+void CopyOutFieldC(uint8_t* out, int len)
+{
+    int count = ((len < 5) ? len : 5);
+    for(int i=0; i<count; i++)
+    {
+        out[i] = GetFieldC(i);
+    }
+}
+/*  , (0 to 255)*/
 uint8_t* FieldC()
 {
     return (uint8_t*)&m_data[6];
 }""")
+        expected.append("""\
+/*  , (-2147483648 to 2147483647)*/
+void CopyInFieldS2_Member1(const int32_t* in, int len)
+{
+    int count = ((len < 3) ? len : 3);
+    for(int i=0; i<count; i++)
+    {
+        SetFieldS2_Member1(in[i], i);
+    }
+}
+/*  , (-2147483648 to 2147483647)*/
+void CopyOutFieldS2_Member1(int32_t* out, int len)
+{
+    int count = ((len < 3) ? len : 3);
+    for(int i=0; i<count; i++)
+    {
+        out[i] = GetFieldS2_Member1(i);
+    }
+}
+""")
+        expected.append("""\
+/*  , (DBL_MIN to DBL_MAX)*/
+void CopyInFieldS2_Member2(const double* in, int len)
+{
+    int count = ((len < 3) ? len : 3);
+    for(int i=0; i<count; i++)
+    {
+        SetFieldS2_Member2(in[i], i);
+    }
+}
+/*  , (DBL_MIN to DBL_MAX)*/
+void CopyOutFieldS2_Member2(double* out, int len)
+{
+    int count = ((len < 3) ? len : 3);
+    for(int i=0; i<count; i++)
+    {
+        out[i] = GetFieldS2_Member2(i);
+    }
+}
+""")
+
+
         expCount = len(expected)
         observed = language.accessors(MsgParser.Messages(self.msgDict)[0])
         obsCount = len(observed)
diff --git a/msgtools/parser/test/TestJava.py b/msgtools/parser/test/TestJava.py
index 6c81c22..d4fcfe6 100755
--- a/msgtools/parser/test/TestJava.py
+++ b/msgtools/parser/test/TestJava.py
@@ -13,7 +13,7 @@ def setUp(self):
         self.maxDiff = None
         with open("messages/TestCase1.yaml", 'r') as inputFile:
             self.msgIDL = inputFile.read()
-        self.msgDict = yaml.load(self.msgIDL)
+        self.msgDict = yaml.load(self.msgIDL, Loader=yaml.SafeLoader)
         PatchStructs(self.msgDict)
 
     def test_accessors(self):
diff --git a/msgtools/parser/test/TestKotlin.py b/msgtools/parser/test/TestKotlin.py
index cc10199..6cbd810 100755
--- a/msgtools/parser/test/TestKotlin.py
+++ b/msgtools/parser/test/TestKotlin.py
@@ -13,7 +13,7 @@ def setUp(self):
         self.maxDiff = None
         with open("messages/TestCase1.yaml", 'r') as inputFile:
             self.msgIDL = inputFile.read()
-        self.msgDict = yaml.load(self.msgIDL)
+        self.msgDict = yaml.load(self.msgIDL, Loader=yaml.SafeLoader)
         PatchStructs(self.msgDict)
 
     def test_accessors(self):
diff --git a/msgtools/parser/test/TestPython.py b/msgtools/parser/test/TestPython.py
index 6065f1e..901e54e 100755
--- a/msgtools/parser/test/TestPython.py
+++ b/msgtools/parser/test/TestPython.py
@@ -13,7 +13,7 @@ def setUp(self):
         self.maxDiff = None
         with open("messages/TestCase1.yaml", 'r') as inputFile:
             self.msgIDL = inputFile.read()
-        self.msgDict = yaml.load(self.msgIDL)
+        self.msgDict = yaml.load(self.msgIDL, Loader=yaml.SafeLoader)
         PatchStructs(self.msgDict)
 
     def test_accessors(self):