Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix improper class.filename and package.name values on XML coverage report #863

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/integrationtest/python/base_itest_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def assert_file_contains(self, name, expected_content_part):
content = file.read()
self.assertTrue(expected_content_part in content)

def assert_file_not_contains(self, name, unexpected_content_part):
full_path = self.full_path(name)
with open(full_path) as file:
content = file.read()
self.assertFalse(unexpected_content_part in content)

def assert_file_content(self, name, expected_file_content):
if expected_file_content == "":
self.assert_file_empty(name)
Expand Down
80 changes: 80 additions & 0 deletions src/integrationtest/python/issue_862_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
#
# This file is part of PyBuilder
#
# Copyright 2011-2022 PyBuilder Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap
import unittest

from itest_support import IntegrationTestSupport


class Issue862Test(IntegrationTestSupport):
def test(self):
self.write_build_file(textwrap.dedent("""
from pybuilder.core import init, use_plugin

use_plugin("python.core")
use_plugin("python.unittest")
use_plugin("python.coverage")

name = "issue_862_tests"

@init
def init(project):
project.set_property("coverage_break_build", False)
"""))

self.create_directory("src/main/python/code")
self.create_directory("src/unittest/python")

self.write_file("src/main/python/code/__init__.py", textwrap.dedent(
"""
from .two import return_two

def return_one():
return 1
"""
))
self.write_file("src/main/python/code/two.py", textwrap.dedent(
"""
def return_two():
return 2
"""
))
self.write_file("src/unittest/python/code_tests.py", textwrap.dedent(
"""
import unittest
import code

class CodeTests(unittest.TestCase):
def test_code(self):
self.assertEqual(code.return_one(), 1)

def test_return_two(self):
self.assertEqual(code.return_two(), 2)
"""))

reactor = self.prepare_reactor()
reactor.build("coverage")

coverage_file_path = "target/reports/issue_862_tests_coverage.xml"
self.assert_file_not_contains(coverage_file_path, 'filename="/')
self.assert_file_not_contains(coverage_file_path, '<package name=".')


if __name__ == "__main__":
unittest.main()
5 changes: 4 additions & 1 deletion src/main/python/pybuilder/plugins/python/coverage_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import ast
import copy
from os.path import dirname
from os.path import dirname, join

import sys

Expand Down Expand Up @@ -106,6 +106,9 @@ def coverage(project, logger, reactor):

source_path = nc(project.expand_path(project.get_property("coverage_source_path")))

# Add a trailing / or \ if not present, for correct `coverage` path interpretation
source_path = join(source_path, "")

module_names = discover_modules(source_path)
module_file_suffixes = discover_module_files(source_path)

Expand Down