Browse Source

Merge branch 'next'

Peter Magnusson 8 years ago
parent
commit
c83dcb4137
9 changed files with 48 additions and 73 deletions
  1. 32 0
      doc/DEVELOP.md
  2. 0 17
      doc/TEST.md
  3. 2 2
      nodemcu_uploader/luacode.py
  4. 2 1
      nodemcu_uploader/uploader.py
  5. 1 0
      test_requirements.txt
  6. 2 1
      tests/__init__.py
  7. 1 1
      tests/misc.py
  8. 8 5
      tests/uploader.py
  9. 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
-```
-

+ 2 - 2
nodemcu_uploader/luacode.py

@@ -31,9 +31,9 @@ function recv_block(d)
     uart.on('data')
   end
 end
-function recv_name(d) d = string.gsub(d, '\000', '') file.remove(d) file.open(d, 'w') uart.on('data', 130, recv_block, 0) uart.write(0, '\006') end
+function recv_name(d) d = d:gsub('%z.*', '') file.remove(d) file.open(d, 'w') uart.on('data', 130, recv_block, 0) uart.write(0, '\006') end
 function recv() uart.on('data', '\000', recv_name, 0) uart.write(0, 'C') end
-function shafile(f) crypto.toHex(crypto.fhash('sha1', f)) end
+function shafile(f) print(crypto.toHex(crypto.fhash('sha1', f))) end
 """
 
 SEND_LUA = \

+ 2 - 1
nodemcu_uploader/uploader.py

@@ -290,8 +290,9 @@ class Uploader(object):
         fil = open(path, 'rb')
         content = fil.read()
         fil.close()
+        log.info('Verifying using %s...' % verify)
         if verify == 'raw':
-            log.info('Verifying...')
+
             data = self.download_file(destination)
             if content != data:
                 log.error('Raw verification failed.')

+ 1 - 0
test_requirements.txt

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

+ 2 - 1
tests/__init__.py

@@ -11,7 +11,8 @@ def get_tests():
 
 def full_suite():
     """creates a full suite of tests"""
-    logging.basicConfig(filename='test-debug.log', level=logging.INFO, format='%(message)s')
+    logging.basicConfig(filename='test.log', level=logging.INFO,
+        ormat='%(asctime)s %(levelname)s %(module)s.%(funcName)s %(message)s')
 
     from .misc import MiscTestCase
     from . import uploader

+ 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)
-
-