Browse Source

Some really basic testing

kmpm 8 years ago
parent
commit
c21e157fdb
8 changed files with 54 additions and 22 deletions
  1. 2 0
      .gitignore
  2. 10 0
      .travis.yml
  3. 0 20
      lib/decorators.py
  4. 2 2
      lib/utils.py
  5. 1 0
      setup.py
  6. 14 0
      tests/__init__.py
  7. 16 0
      tests/misc.py
  8. 9 0
      tests/uploader.py

+ 2 - 0
.gitignore

@@ -1,6 +1,8 @@
 *.egg-info/
+.eggs
 dist/
 build/
 *.pyc
+.coverage
 
 .vscode/

+ 10 - 0
.travis.yml

@@ -0,0 +1,10 @@
+language: python
+python:
+  - "2.7"
+
+# command to install dependencies
+#install: "pip install -r requirements.txt"
+
+# command to run tests
+script:
+  - coverage run setup.py test

+ 0 - 20
lib/decorators.py

@@ -1,20 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (C) 2015-2016 Peter Magnusson <peter@birchroad.net>
-"""Decorators used in the module"""
-
-import warnings
-
-def deprecated(func):
-    """This is a decorator which can be used to mark functions
-    as deprecated. It will result in a warning being emmitted
-    when the function is used."""
-    def new_func(*args, **kwargs):
-        """whatever"""
-        warnings.warn("Call to deprecated function %s." % func.__name__,
-                      category=DeprecationWarning)
-        return func(*args, **kwargs)
-    new_func.__name__ = func.__name__
-    new_func.__doc__ = func.__doc__
-    new_func.__dict__.update(func.__dict__)
-    return new_func
-

+ 2 - 2
lib/utils.py

@@ -4,10 +4,10 @@
 
 from platform import system
 
-def default_port():
+def default_port(sysname = system()):
     """This returns the default port used for different systems"""
     return {
         'Windows': 'COM1',
         'Darwin': '/dev/tty.SLAB_USBtoUART'
-    }.get(system(), '/dev/ttyUSB0')
+    }.get(sysname, '/dev/ttyUSB0')
 

+ 1 - 0
setup.py

@@ -20,6 +20,7 @@ setup(name='nodemcu-uploader',
           'Programming Language :: Python :: 2.7'
       ],
       license='MIT',
+      test_suite = "tests.get_tests",
       entry_points={
           'console_scripts': [
               'nodemcu-uploader=nodemcu_uploader.main:main_func'

+ 14 - 0
tests/__init__.py

@@ -0,0 +1,14 @@
+import unittest
+
+def get_tests():
+    return full_suite()
+
+def full_suite():
+    from .misc import MiscTestCase
+    from .uploader import UploaderTestCase
+    # from .serializer import ResourceTestCase as SerializerTestCase
+    # from .utils import UtilsTestCase
+
+    miscsuite = unittest.TestLoader().loadTestsFromTestCase(MiscTestCase)
+    uploadersuite = unittest.TestLoader().loadTestsFromTestCase(UploaderTestCase)
+    return unittest.TestSuite([miscsuite, uploadersuite])

+ 16 - 0
tests/misc.py

@@ -0,0 +1,16 @@
+import unittest
+from lib.utils import default_port
+from lib import __version__
+
+class MiscTestCase(unittest.TestCase):
+
+    def test_version(self):
+        self.assertEqual(__version__, '0.2.0')
+
+    def test_default_port(self):
+        #Test as if it were given system
+        self.assertEqual(default_port('Linux'), '/dev/ttyUSB0')
+        self.assertEqual(default_port('Windows'), 'COM1')
+        self.assertEqual(default_port('Darwin'), '/dev/tty.SLAB_USBtoUART')
+
+        self.assertTrue(len(default_port()) >= 3)

+ 9 - 0
tests/uploader.py

@@ -0,0 +1,9 @@
+import unittest
+from lib import Uploader, __version__
+
+class UploaderTestCase(unittest.TestCase):
+
+
+
+    def test_initialize(self):
+        uploader = Uploader()