Repository: nexdatas/sardana-nxs-filerecorder (language: python)

Issue:
add version tests
It would be good to add first tests


Discussion / hints:

Fix patch:
diff --git a/.ci/install.sh b/.ci/install.sh
index a2e50a9..5ed2fbb 100644
--- a/.ci/install.sh
+++ b/.ci/install.sh
@@ -96,13 +96,13 @@ if [[ "$2" == "2" ]]; then
 else
     echo "install sardana, taurus and nexdatas"
     docker exec  --user root ndts /bin/bash -c 'export DEBIAN_FRONTEND=noninteractive; apt-get -qq update; apt-get install -y  nxsconfigserver-db; sleep 10; apt-get -qq install -y python3-nxsconfigserver python3-nxswriter python3-nxstools python3-nxsrecselector python3-setuptools nxsrecselector3 nxswriter3 nxsconfigserver3 nxstools3 python3-packaging'
-    if  [ "$1" = "ubuntu20.04" ] || [ "$1" = "ubuntu20.10" ] || [ "$1" = "debian11" ]  || [ "$1" = "ubuntu22.04" ] ; then
-	docker exec  --user root ndts /bin/bash -c 'export DEBIAN_FRONTEND=noninteractive;  apt-get -qq update; apt-get -qq install -y python3-taurus python3-sardana'
-    else
+    if  [ "$1" == "ubuntu18.04" ] ; then
 	docker exec  --user root ndts /bin/bash -c 'git clone https://gitlab.com/taurus-org/taurus taurus-src; cd taurus-src'
 	docker exec  --user root ndts /bin/bash -c 'cd taurus-src; git checkout tags/4.7.0 -b b4.7.0; python3 setup.py install'
 	docker exec  --user root ndts /bin/bash -c 'git clone https://github.com/sardana-org/sardana sardana-src; cd sardana-src'
 	docker exec  --user root ndts /bin/bash -c 'cd sardana-src; git checkout tags/3.1.0 -b b3.1.0; python3 setup.py install'
+    else
+	docker exec  --user root ndts /bin/bash -c 'export DEBIAN_FRONTEND=noninteractive;  apt-get -qq update; apt-get -qq install -y python3-taurus python3-sardana'
     fi
 fi
 if [ "$?" -ne "0" ]; then exit 255; fi


Test patch:
diff --git a/test/main.py b/test/main.py
index f085dc2..d1f2f23 100755
--- a/test/main.py
+++ b/test/main.py
@@ -23,6 +23,7 @@
 import sys
 import unittest
 
+import nxsfilerecorder_test
 
 try:
     __import__("PyTango")
@@ -33,15 +34,11 @@
     print("PyTango is not available: %s" % e)
 
 try:
-    try:
-        __import__("pni.io.nx.h5")
-    except Exception:
-        __import__("pni.nx.h5")
-    # if module pni avalable
-    PNI_AVAILABLE = True
+    __import__("pninexus")
+    PNINEXUS_AVAILABLE = True
 except ImportError as e:
-    PNI_AVAILABLE = False
-    print("pni is not available: %s" % e)
+    PNINEXUS_AVAILABLE = False
+    print("pninexus is not available: %s" % e)
 
 try:
     __import__("h5py")
@@ -52,12 +49,12 @@
     print("h5py is not available: %s" % e)
 
 
-if not PNI_AVAILABLE and not H5PY_AVAILABLE:
-    raise Exception("Please install h5py or pni")
+if not PNINEXUS_AVAILABLE and not H5PY_AVAILABLE:
+    raise Exception("Please install h5py or pninexus")
 
-# if PNI_AVAILABLE:
+# if PNINEXUS_AVAILABLE:
 # if H5PY_AVAILABLE:
-# if PNI_AVAILABLE and H5PY_AVAILABLE:
+# if PNINEXUS_AVAILABLE and H5PY_AVAILABLE:
 
 # list of available databases
 DB_AVAILABLE = []
@@ -144,9 +141,10 @@ def main():
     # db = PyTango.Database()
     suite = unittest.TestSuite()
 
-    # suite.addTests(
-    #     unittest.defaultTestLoader.loadTestsFromModule(
-    #           DBFieldTagAsynchH5PYTest) )
+    suite.addTests(
+          unittest.defaultTestLoader.loadTestsFromModule(
+              nxsfilerecorder_test)
+    )
 
     # test runner
     runner = unittest.TextTestRunner()
diff --git a/test/nxsfilerecorder_test.py b/test/nxsfilerecorder_test.py
new file mode 100644
index 0000000..5634585
--- /dev/null
+++ b/test/nxsfilerecorder_test.py
@@ -0,0 +1,136 @@
+#!/usr/bin/env python
+#   This file is part of nexdatas - Tango Server for NeXus data writer
+#
+#    Copyright (C) 2012-2018 DESY, Jan Kotanski <jkotan@mail.desy.de>
+#
+#    nexdatas is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    nexdatas is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with nexdatas.  If not, see <http://www.gnu.org/licenses/>.
+# \package test nexdatas
+# \file XMLConfiguratorTest.py
+# unittests for field Tags running Tango Server
+#
+import unittest
+import os
+import sys
+import random
+import struct
+import binascii
+
+if sys.version_info > (3,):
+    unicode = str
+    long = int
+
+
+# if 64-bit machione
+IS64BIT = (struct.calcsize("P") == 8)
+
+# from nxsconfigserver.XMLConfigurator  import XMLConfigurator
+# from nxsconfigserver.Merger import Merger
+# from nxsconfigserver.Errors import (
+# NonregisteredDBRecordError, UndefinedTagError,
+#                                    IncompatibleNodeError)
+# import nxsconfigserver
+
+
+def myinput(w, text):
+    myio = os.fdopen(w, 'w')
+    myio.write(text)
+
+    # myio.close()
+
+
+# test fixture
+class NXSFileRecorderTest(unittest.TestCase):
+
+    # constructor
+    # \param methodName name of the test method
+    def __init__(self, methodName):
+        unittest.TestCase.__init__(self, methodName)
+
+        try:
+            # random seed
+            self.seed = long(binascii.hexlify(os.urandom(16)), 16)
+        except NotImplementedError:
+            import time
+            # random seed
+            self.seed = long(time.time() * 256)  # use fractional seconds
+
+        self.__rnd = random.Random(self.seed)
+
+        self._bint = "int64" if IS64BIT else "int32"
+        self._buint = "uint64" if IS64BIT else "uint32"
+        self._bfloat = "float64" if IS64BIT else "float32"
+
+        # from os.path import expanduser
+        # home = expanduser("~")
+
+    # test starter
+    # \brief Common set up
+    def setUp(self):
+        print("\nsetting up...")
+        print("SEED = %s" % self.seed)
+
+    # test closer
+    # \brief Common tear down
+    def tearDown(self):
+        print("tearing down ...")
+
+    # Exception tester
+    # \param exception expected exception
+    # \param method called method
+    # \param args list with method arguments
+    # \param kwargs dictionary with method arguments
+    def myAssertRaise(self, exception, method, *args, **kwargs):
+        try:
+            error = False
+            method(*args, **kwargs)
+        except Exception:
+            error = True
+        self.assertEqual(error, True)
+
+    # comp_available test
+    # \brief It tests NXSelector
+    def test_version(self):
+        fun = sys._getframe().f_code.co_name
+        print("Run: %s.%s() " % (self.__class__.__name__, fun))
+
+        try:
+            from sardananxsrecorder import nxsrecorder
+            nxsrecorder
+            error = False
+        except Exception as e:
+            print(e)
+            error = e
+        self.assertTrue(bool(nxsrecorder))
+        self.assertTrue(not bool(error))
+
+        try:
+            import sardananxsrecorder
+            ver = sardananxsrecorder.__version__
+            error = False
+        except Exception as e:
+            print(e)
+            ver = None
+            error = e
+        self.assertTrue("." in ver)
+        self.assertTrue(not bool(error))
+
+        # if not error:
+        #     import sardananxsrecorder
+        #     fname = '%s/%s%s.nxs' % (
+        #         os.getcwd(), self.__class__.__name__, fun)
+        #     rec = nxsrecorder.NXS_FileRecorder(fname)
+
+
+if __name__ == '__main__':
+    unittest.main()