Return code matches now the number of error occurred during tests 31/18331/1
authorThomas Duval <thomas.duval@orange.com>
Wed, 10 Aug 2016 13:45:39 +0000 (15:45 +0200)
committerThomas Duval <thomas.duval@orange.com>
Wed, 10 Aug 2016 13:45:39 +0000 (15:45 +0200)
Change-Id: I9de79187b12750003d5785048c6b929edff55468

moonclient/Changelog
moonclient/moonclient/__init__.py
moonclient/moonclient/shell.py
moonclient/moonclient/tests.py
moonclient/setup.py

index 0ba076c..f641f3a 100644 (file)
@@ -7,6 +7,11 @@
 CHANGES
 =======
 
+0.3.0
+-----
+
+* Return code matches now the number of error occurred during tests
+
 0.2.0
 -----
 
index f3d87ba..d1d0251 100644 (file)
@@ -11,42 +11,7 @@ import os
 
 from cliff.app import App
 from cliff.commandmanager import CommandManager
-from cliff.formatters.base import ListFormatter, SingleFormatter
-
-
-class _JSONFormatter(ListFormatter, SingleFormatter):
-
-    def add_argument_group(self, parser):
-        group = parser.add_argument_group(title='json formatter')
-        group.add_argument(
-            '--noindent',
-            action='store_true',
-            dest='noindent',
-            help='whether to disable indenting the JSON'
-        )
-        group.add_argument(
-            '--projectname',
-            help='Set the project name'
-        )
-
-    def emit_list(self, column_names, data, stdout, parsed_args):
-        items = []
-        import time
-        for item in data:
-            element = dict(zip(column_names, item))
-            element["project_name"] = parsed_args.projectname
-            element["name"] = element.pop("test_name")
-            element["url"] = ""
-            element["_id"] = ""
-            element["creation_date"] = time.strftime("%Y-%m-%d %H:%M:%S")
-            items.append(element)
-        indent = None if parsed_args.noindent else 2
-        json.dump({"testcases": items}, stdout, indent=indent)
-
-    def emit_one(self, column_names, data, stdout, parsed_args):
-        one = dict(zip(column_names, data))
-        indent = None if parsed_args.noindent else 2
-        json.dump(one, stdout, indent=indent)
+import moonclient
 
 
 def get_env_creds(admin_token=False):
@@ -76,6 +41,7 @@ class MoonClient(App):
     secureprotocol = False
     user_saving_file = ".moonclient"
     url_prefix = "/moon"
+    _nb_error = 0
     post = {
         "auth": {
             "identity": {
@@ -106,7 +72,7 @@ class MoonClient(App):
     def __init__(self):
         super(MoonClient, self).__init__(
             description='Moon Python Client',
-            version='0.2.0',
+            version=moonclient.__version__,
             command_manager=CommandManager('moon.client'),
             )
         creds = get_env_creds()
@@ -165,6 +131,14 @@ class MoonClient(App):
         self._intraextension = value
         open(os.path.join(os.getenv('HOME'), self.user_saving_file), "w").write(value)
 
+    @property
+    def nb_error(self):
+        return self._nb_error
+
+    def incr_error(self):
+        self._nb_error += 1
+        print("INCREMENTING ERRORS {}".format(self._nb_error))
+
     def get_tenant_uuid(self, tenant_name):
         return self.get_url("/v3/projects?name={}".format(tenant_name), authtoken=True, port=5000)["projects"][0]["id"]
 
@@ -266,8 +240,6 @@ class MoonClient(App):
         data = self.get_url("/v3/auth/tokens", post_data=self.post)
         if "token" not in data:
             raise Exception("Authentication problem ({})".format(data))
-        from cliff.formatters.json_format import JSONFormatter
-        JSONFormatter = _JSONFormatter
 
     def prepare_to_run_command(self, cmd):
         self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__)
@@ -281,7 +253,8 @@ class MoonClient(App):
 
 def main(argv=sys.argv[1:]):
     myapp = MoonClient()
-    return myapp.run(argv)
+    myapp.run(argv)
+    return myapp.nb_error
 
 
 if __name__ == '__main__':
index f312eed..de93dc6 100644 (file)
@@ -203,6 +203,7 @@ class TestsLaunch(Lister):
                         overall_result = overall_result and True
                     else:
                         compare = "\033[1m\033[31mFalse\033[m"
+                        self.app.incr_error()
                         overall_result = overall_result and False
                 else:
                     overall_result = overall_result and compare
@@ -213,6 +214,7 @@ class TestsLaunch(Lister):
                             compare = "\033[mTrue\033[m"
                     else:
                         compare = "\033[1m\033[31mFalse\033[m"
+                        self.app.incr_error()
                 data_tmp.append(compare)
                 data_tmp.append(test["description"])
                 data.append(data_tmp)
index 71ea704..0b93c4d 100644 (file)
@@ -5,13 +5,13 @@
 # This software is distributed under the terms and conditions of the 'Apache-2.0'
 # license which can be found in the file 'LICENSE' in this package distribution
 # or at 'http://www.apache.org/licenses/LICENSE-2.0'.
+from setuptools import setup, find_packages
+from moonclient import __version__
 
 PROJECT = 'python-moonclient'
 
 # Change docs/sphinx/conf.py too!
-VERSION = '0.1'
-
-from setuptools import setup, find_packages
+VERSION = __version__
 
 try:
     long_description = open('README.rst', 'rt').read()