You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/07/20 15:52:07 UTC
[skywalking-python] 01/01: Test: print the diff list when
validation failed
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch test/diff-when-failed
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit e1b2330fbc491155d7e4c48e03fd13261b8ffe8f
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Mon Jul 20 23:51:57 2020 +0800
Test: print the diff list when validation failed
---
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