This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
The following commit(s) were added to refs/heads/master by this push: new d3c13bf Test: print the diff list when validation failed (#46) d3c13bf is described below commit d3c13bf8e35360ee0541e97ff607d12c4524d281 Author: kezhenxu94 <kezhenx...@apache.org> AuthorDate: Tue Jul 21 21:38:03 2020 +0800 Test: print the diff list when validation failed (#46) --- setup.py | 1 + tests/plugin/__init__.py | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 6511078..8ef00a0 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ setup( extras_require={ "test": [ "testcontainers", + "pyyaml", "Werkzeug", "pymysql", "redis", diff --git a/tests/plugin/__init__.py b/tests/plugin/__init__.py index e6d912d..f858a1f 100644 --- a/tests/plugin/__init__.py +++ b/tests/plugin/__init__.py @@ -16,15 +16,23 @@ # import inspect import os +import sys import unittest from abc import ABC from collections import namedtuple +from difflib import Differ from os.path import dirname import requests +import yaml from requests import Response from testcontainers.compose import DockerCompose +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader + HostPort = namedtuple('HostPort', 'host port') ServicePort = namedtuple('ServicePort', 'service port') @@ -72,12 +80,28 @@ class BasePluginTest(unittest.TestCase, ABC): expected_file_name = os.path.join(dirname(inspect.getfile(self.__class__)), 'expected.data.yml') with open(expected_file_name) as expected_data_file: + expected_data = os.linesep.join(expected_data_file.readlines()) + response = requests.post( url=self.__class__.url(self.__class__.collector_address(), path='/dataValidate'), - data=os.linesep.join(expected_data_file.readlines()), + data=expected_data, ) - print('validate: ', response) - self.assertEqual(response.status_code, 200) + if response.status_code != 200: + res = requests.get(url=self.__class__.url(self.__class__.collector_address(), path='/receiveData')) + + actual_data = yaml.dump(yaml.load(res.content, Loader=Loader)) + + differ = Differ() + diff_list = list(differ.compare( + actual_data.splitlines(keepends=True), + yaml.dump(yaml.load(expected_data, Loader=Loader)).splitlines(keepends=True) + )) + + print('diff list: ') + + sys.stdout.writelines(diff_list) + + self.assertEqual(response.status_code, 200) - return response + return response