From 69eac92a05b5dd61293b9787d5d35a8e3559bf0d Mon Sep 17 00:00:00 2001 From: xumia Date: Tue, 13 Jul 2021 09:21:35 +0000 Subject: [PATCH 1/2] Support azp diff coverage --- azure-pipelines.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6b4455d6..7a2117a3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,6 +30,15 @@ stages: clean: true submodules: recursive displayName: 'Checkout code' + - script: | + set -x + wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + sudo dpkg -i packages-microsoft-prod.deb + sudo apt-get update + sudo apt-get install -y dotnet-sdk-5.0 + sudo pip3 install pytest pytest-azurepipelines + sudo pip3 install pytest-cov + displayName: "Install build tools" - script: | set -ex @@ -41,14 +50,21 @@ stages: set -ex sudo python3 -m pip install dist/swsssdk-2.0.1-py3-none-any.whl - python3 setup.py test + python3 -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml displayName: "Unit tests" + - script: | + sudo pip3 install diff-cover + target_branch=$(System.PullRequest.TargetBranch) + compare_branch=origin/${target_branch#refs/heads/} + diff-cover coverage.xml --compare-branch=$compare_branch + condition: eq(variables['Build.Reason'], 'PullRequest') + displayName: "Diff coverage" - publish: $(Build.ArtifactStagingDirectory) artifact: sonic-py-swsssdk displayName: "Archive artifacts" - task: PublishTestResults@2 inputs: - testResultsFiles: '$(System.DefaultWorkingDirectory)/test-results.xml' + testResultsFiles: '**/test-*.xml' testRunTitle: Python 3 failTaskOnFailedTests: true condition: succeededOrFailed() @@ -56,6 +72,6 @@ stages: - task: PublishCodeCoverageResults@1 inputs: codeCoverageTool: Cobertura - summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml' - reportDirectory: '$(System.DefaultWorkingDirectory)/htmlcov/' + summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml' + additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/*.coverage' displayName: 'Publish Python 3 test coverage' From 9e927a688896408f63cea2913ad483e539e34269 Mon Sep 17 00:00:00 2001 From: xumia Date: Tue, 13 Jul 2021 09:22:56 +0000 Subject: [PATCH 2/2] Test diff coverage --- src/swsssdk/configdb.py | 1 + src/swsssdk/dbconnector.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/swsssdk/configdb.py b/src/swsssdk/configdb.py index 95aeb2ba..c5bcd8e6 100644 --- a/src/swsssdk/configdb.py +++ b/src/swsssdk/configdb.py @@ -55,6 +55,7 @@ def __init__(self, decode_responses=True, **kwargs): self.TABLE_NAME_SEPARATOR = '|' self.KEY_SEPARATOR = '|' self.handlers = {} + self.test_cover = '' def __wait_for_db_init(self): client = self.get_redis_client(self.db_name) diff --git a/src/swsssdk/dbconnector.py b/src/swsssdk/dbconnector.py index d2636399..4a779d25 100644 --- a/src/swsssdk/dbconnector.py +++ b/src/swsssdk/dbconnector.py @@ -36,6 +36,8 @@ def load_sonic_global_db_config(global_db_file_path=SONIC_DB_GLOBAL_CONFIG_FILE, if os.path.isfile(global_db_file_path): global_db_config_dir = os.path.dirname(global_db_file_path) + if global_db_file_path is None: + global_db_file_path = None with open(global_db_file_path, "r") as read_file: all_ns_dbs = json.load(read_file) for entry in all_ns_dbs['INCLUDES']: @@ -209,6 +211,8 @@ def get_socket(db_name, namespace=None): @staticmethod def get_hostname(db_name, namespace=None): namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace) + if namespace == None: + namespace = None if not SonicDBConfig._sonic_db_config_init: SonicDBConfig.load_sonic_db_config() return SonicDBConfig.get_instance(db_name, namespace)["hostname"]