Browse Source

added nose tests to check if configuration validation works as expected

twall 11 năm trước cách đây
mục cha
commit
a1d547ffef

+ 0 - 0
nsist/tests/__init__.py


+ 19 - 0
nsist/tests/data_files/invalid_config_keys.cfg

@@ -0,0 +1,19 @@
+[JamesBrown]
+name=My App
+version=1.0
+# How to launch the app - this calls the 'main' function from the 'myapp' package:
+entry_point=myapp:main
+icon=myapp.ico
+
+[Python]
+version=3.4.0
+
+[Include]
+# Importable packages that your application requires, one per line
+packages = requests
+     bs4
+     html5lib
+
+# Other files and folders that should be installed
+files = LICENSE
+    data_files/

+ 20 - 0
nsist/tests/data_files/invalid_config_subsection.cfg

@@ -0,0 +1,20 @@
+[Application]
+name=My App
+version=1.0
+# How to launch the app - this calls the 'main' function from the 'myapp' package:
+entry_point=myapp:main
+icon=myapp.ico
+this_subsection=is_invalid
+
+[Python]
+version=3.4.0
+
+[Include]
+# Importable packages that your application requires, one per line
+packages = requests
+     bs4
+     html5lib
+
+# Other files and folders that should be installed
+files = LICENSE
+    data_files/

+ 18 - 0
nsist/tests/data_files/missing_config_subsection.cfg

@@ -0,0 +1,18 @@
+[Application]
+version=1.0
+# How to launch the app - this calls the 'main' function from the 'myapp' package:
+entry_point=myapp:main
+icon=myapp.ico
+
+[Python]
+version=3.4.0
+
+[Include]
+# Importable packages that your application requires, one per line
+packages = requests
+     bs4
+     html5lib
+
+# Other files and folders that should be installed
+files = LICENSE
+    data_files/

+ 1 - 0
nsist/tests/data_files/not_a_config.cfg

@@ -0,0 +1 @@
+THIS IS NOT A CONFIG FILE!

+ 19 - 0
nsist/tests/data_files/valid_config.cfg

@@ -0,0 +1,19 @@
+[Application]
+name=My App
+version=1.0
+# How to launch the app - this calls the 'main' function from the 'myapp' package:
+entry_point=myapp:main
+icon=myapp.ico
+
+[Python]
+version=3.4.0
+
+[Include]
+# Importable packages that your application requires, one per line
+packages = requests
+     bs4
+     html5lib
+
+# Other files and folders that should be installed
+files = LICENSE
+    data_files/

+ 29 - 0
nsist/tests/test_configuration_validator.py

@@ -0,0 +1,29 @@
+from nose.tools import *
+import os
+from nsist import read_and_verify_config_file
+
+DATA_FILES = os.path.join(os.path.dirname(__file__), 'data_files')
+
+def test_valid_config():
+    configfile = os.path.join(DATA_FILES, 'valid_config.cfg')
+    read_and_verify_config_file(configfile)
+
+@raises(NameError)
+def test_invalid_config_keys():
+    configfile = os.path.join(DATA_FILES, 'invalid_config_keys.cfg')
+    read_and_verify_config_file(configfile)
+
+@raises(NameError)
+def test_invalid_config_subsection():
+    configfile = os.path.join(DATA_FILES, 'invalid_config_subsection.cfg')
+    read_and_verify_config_file(configfile)
+
+@raises(NameError)
+def test_missing_config_subsection():
+    configfile = os.path.join(DATA_FILES, 'missing_config_subsection.cfg')
+    read_and_verify_config_file(configfile)
+
+@raises(Exception)
+def test_invalid_config_file():
+    configfile = os.path.join(DATA_FILES, 'not_a_config.cfg')
+    read_and_verify_config_file(configfile)