Browse Source

some test updates

kmpm 8 years ago
parent
commit
d702252a34
6 changed files with 42 additions and 69 deletions
  1. 32 0
      doc/DEVELOP.md
  2. 0 17
      doc/TEST.md
  3. 1 0
      test_requirements.txt
  4. 1 1
      tests/misc.py
  5. 8 5
      tests/uploader.py
  6. 0 46
      tests/winserial.py

+ 32 - 0
doc/DEVELOP.md

@@ -0,0 +1,32 @@
+Develop and Test nodemcu-uploader
+=================================
+
+Configure development environment
+-------
+```
+git clone https://github.com/kmpm/nodemcu-uploader
+cd nodemcu-uploader
+virtualenv env
+. env/bin/activate
+pip install -r test_requirements.txt
+python setyp.py develop
+```
+
+
+
+Testing
+-------
+```
+pip install -r test_requirements.txt
+coverage run setup.py test
+```
+
+To run tests that actually communicate with a device you
+will need to set the __SERIALPORT__ environment variable
+to the port where you have an device connected.
+
+Linux
+```
+export SERIALPORT=/dev/ttyUSB0
+```
+

+ 0 - 17
doc/TEST.md

@@ -1,17 +0,0 @@
-Testing nodemcu-uploader
-========================
-
-```
-pip install -r test_requirements.txt
-coverage run setup.py test
-```
-
-To run tests that actually communicate with a device you
-will need to set the __SERIALPORT__ environment variable
-to the port where you have an device connected.
-
-Linux
-```
-export SERIALPORT=/dev/ttyUSB0
-```
-

+ 1 - 0
test_requirements.txt

@@ -1 +1,2 @@
+pyserial==3.0.1
 coverage==4.0.3

+ 1 - 1
tests/misc.py

@@ -8,7 +8,7 @@ import os
 class MiscTestCase(unittest.TestCase):
 
     def test_version(self):
-        self.assertEqual(__version__, '0.3.0')
+        self.assertEqual(__version__, '0.3.1')
 
     def test_default_port(self):
         if os.environ.get('SERIALPORT', 'none') != 'none':

+ 8 - 5
tests/uploader.py

@@ -4,6 +4,8 @@
 import unittest
 import os, time
 from nodemcu_uploader import Uploader
+from serial import VERSION as serialversion
+from distutils.version import LooseVersion
 
 LOOPPORT = 'loop://'
 
@@ -15,11 +17,12 @@ def is_real():
         return False
     return str(SERIALPORT) != str(LOOPPORT)
 
-# class UploaderFakeTestCase(unittest.TestCase):
-#     def test_init(self):
-#         print "SP", SERIALPORT
-#         uploader = Uploader(SERIALPORT)
-#         uploader.close()
+@unittest.skipUnless(LooseVersion(serialversion) >= LooseVersion('3.0.0') , 'Needs pySerial >= 3.0.0')
+class UploaderFakeTestCase(unittest.TestCase):
+    def test_init(self):
+        print "SP", SERIALPORT
+        uploader = Uploader(SERIALPORT)
+        uploader.close()
 
 @unittest.skipUnless(is_real(), 'Needs a configured SERIALPORT')
 class UploaderTestCase(unittest.TestCase):

+ 0 - 46
tests/winserial.py

@@ -1,46 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 2015-2016 Peter Magnusson <peter@birchroad.net>
-import unittest
-import os
-import serial
-from nodemcu_uploader.utils import default_port
-import time
-
-SERIALPORT = os.environ.get('SERIALPORT', default_port())
-
-def expect(port, timeout, exp='> '):
-    timeout = port.timeout
-    # lt = 0.0001
-    # if port.timeout != lt:
-    #     port.timeout = lt
-    end = time.time() + timeout
-
-    data = ''
-    while not data.endswith(exp) and time.time() <= end:
-        data += port.read()
-
-    # port.timeout = timeout
-
-    return data
-
-
-
-class WinSerialCase(unittest.TestCase):
-    port = None
-    def setUp(self):
-        self.port = serial.serial_for_url(SERIALPORT, 9600, timeout=5)
-
-    def tearDown(self):
-        self.port.close()
-
-    def test_sync(self):
-        self.port.write('print("%self%");\n'.encode())
-        expect(self.port, 3)
-
-        for i in range(50):
-            self.port.write('print("%self%");\n'.encode())
-            res = expect(self.port, 1)
-            self.assertEqual(res, 'print("%self%");\r\n%self%\r\n> ')
-            time.sleep(0.2)
-
-