Exemplo n.º 1
0
class TestCoverage(TestCase):
    def setUp(self):
        self._coverage_processor = CoverageProcessor()

    def test_xml_not_found(self):
        additions = {}
        xml_path = 'not/found/path.xml'

        self.assertRaises(NoSuchCoverageException,
                          self._coverage_processor.get_missing_coverage,
                          additions, xml_path)

    def test_get_missing_coverage(self):
        additions = {
            '/foo/bar/hello/world.php': [3, 23, 25, 29],
            '/foo/bar/hello/xxx.php': [1, 2, 3]
        }
        xml_path = '{base_path}/fixtures/coverage.xml'.format(
            base_path=os.path.dirname(os.path.realpath(__file__)))

        missing_coverage = self._coverage_processor.get_missing_coverage(
            additions, xml_path)
        self.assertEqual(1, len(missing_coverage))
        self.assertEqual(2, len(missing_coverage['/foo/bar/hello/world.php']))
        self.assertIn(25, missing_coverage['/foo/bar/hello/world.php'])
        self.assertIn(23, missing_coverage['/foo/bar/hello/world.php'])

    def test_invalid_xml(self):
        additions = {}
        xml_path = '{base_path}/fixtures/invalid_coverage.xml'.format(
            base_path=os.path.dirname(os.path.realpath(__file__)))

        self.assertRaises(InvalidCoverageException,
                          self._coverage_processor.get_missing_coverage,
                          additions, xml_path)
Exemplo n.º 2
0
    def __init__(self):
        parser = argparse.ArgumentParser(
            description="Check the uncovered code lines which have been modified or added in an specific pull request or commit"
        )
        parser.add_argument(
            "--base",
            "-b",
            type=str,
            default="HEAD~1",
            help="Base branch, tag, commit, or history marker to compare the current revision",
        )
        parser.add_argument("--concise", "-c", action="store_true", help="Only display the affected uncovered lines")
        parser.add_argument("--xml", "-x", type=str, default="coverage.xml", help="Path of the generated coverage .xml")
        parser.add_argument("--repository", "-r", type=str, default=None, help="Path of the git repository")
        parser.add_argument(
            "--silently",
            "-s",
            action="store_true",
            help="Even with missing coverage, exit with success system exit status",
        )
        parser.set_defaults(concise=False)

        args = parser.parse_args()

        self._additions_finder = AdditionsFinder()
        self._coverage_processor = CoverageProcessor()
        self._base = args.base
        self._xml = args.xml
        self._repository = args.repository
        if self._repository is None:
            self._repository = getcwd()

        self._concise = args.concise
        self._silently = args.silently
Exemplo n.º 3
0
    def __init__(self):
        parser = argparse.ArgumentParser(
            description=
            'Check the uncovered code lines which have been modified or added in an specific pull request or commit'
        )
        parser.add_argument(
            '--base',
            '-b',
            type=str,
            default='HEAD~1',
            help=
            'Base branch, tag, commit, or history marker to compare the current revision'
        )
        parser.add_argument('--concise',
                            '-c',
                            action='store_true',
                            help='Only display the affected uncovered lines')
        parser.add_argument('--xml',
                            '-x',
                            type=str,
                            default='coverage.xml',
                            help='Path of the generated coverage .xml')
        parser.add_argument('--repository',
                            '-r',
                            type=str,
                            default=None,
                            help='Path of the git repository')
        parser.add_argument(
            '--silently',
            '-s',
            action='store_true',
            help=
            'Even with missing coverage, exit with success system exit status')
        parser.set_defaults(concise=False)

        args = parser.parse_args()

        self._additions_finder = AdditionsFinder()
        self._coverage_processor = CoverageProcessor()
        self._base = args.base
        self._xml = args.xml
        self._repository = args.repository
        if self._repository is None:
            self._repository = getcwd()

        self._concise = args.concise
        self._silently = args.silently
Exemplo n.º 4
0
class Application:
    def __init__(self):
        parser = argparse.ArgumentParser(
            description="Check the uncovered code lines which have been modified or added in an specific pull request or commit"
        )
        parser.add_argument(
            "--base",
            "-b",
            type=str,
            default="HEAD~1",
            help="Base branch, tag, commit, or history marker to compare the current revision",
        )
        parser.add_argument("--concise", "-c", action="store_true", help="Only display the affected uncovered lines")
        parser.add_argument("--xml", "-x", type=str, default="coverage.xml", help="Path of the generated coverage .xml")
        parser.add_argument("--repository", "-r", type=str, default=None, help="Path of the git repository")
        parser.add_argument(
            "--silently",
            "-s",
            action="store_true",
            help="Even with missing coverage, exit with success system exit status",
        )
        parser.set_defaults(concise=False)

        args = parser.parse_args()

        self._additions_finder = AdditionsFinder()
        self._coverage_processor = CoverageProcessor()
        self._base = args.base
        self._xml = args.xml
        self._repository = args.repository
        if self._repository is None:
            self._repository = getcwd()

        self._concise = args.concise
        self._silently = args.silently

    def run(self):
        try:
            additions = self._additions_finder.get_additions_for_base(self._base, self._repository)
            missing_coverage = self._coverage_processor.get_missing_coverage(additions, self._xml)

            if missing_coverage:
                visualizer = Display()
                visualizer.display_missing_coverage(missing_coverage, self._concise)
                if not self._silently:
                    sys.exit(2)
            else:
                print("\033[32m100% relevant lines covered\033[m")
        except Exception as e:
            print("\033[31m %s\033[m" % e.message)
            sys.exit(2)
Exemplo n.º 5
0
class TestCoverage(TestCase):
    def setUp(self):
        self._coverage_processor = CoverageProcessor()

    def test_xml_not_found(self):
        additions = {}
        xml_path = 'not/found/path.xml'

        self.assertRaises(
            NoSuchCoverageException,
            self._coverage_processor.get_missing_coverage,
            additions,
            xml_path
        )

    def test_get_missing_coverage(self):
        additions = {
            '/foo/bar/hello/world.php': [3, 23, 25, 29],
            '/foo/bar/hello/xxx.php': [1, 2, 3]
        }
        xml_path = '{base_path}/fixtures/coverage.xml'.format(base_path=os.path.dirname(os.path.realpath(__file__)))

        missing_coverage = self._coverage_processor.get_missing_coverage(additions, xml_path)
        self.assertEqual(1, len(missing_coverage))
        self.assertEqual(2, len(missing_coverage['/foo/bar/hello/world.php']))
        self.assertIn(25, missing_coverage['/foo/bar/hello/world.php'])
        self.assertIn(23, missing_coverage['/foo/bar/hello/world.php'])

    def test_invalid_xml(self):
        additions = {}
        xml_path = '{base_path}/fixtures/invalid_coverage.xml'.format(base_path=os.path.dirname(os.path.realpath(__file__)))

        self.assertRaises(
            InvalidCoverageException,
            self._coverage_processor.get_missing_coverage,
            additions,
            xml_path
        )
Exemplo n.º 6
0
 def setUp(self):
     self._coverage_processor = CoverageProcessor()
Exemplo n.º 7
0
class Application:
    def __init__(self):
        parser = argparse.ArgumentParser(
            description=
            'Check the uncovered code lines which have been modified or added in an specific pull request or commit'
        )
        parser.add_argument(
            '--base',
            '-b',
            type=str,
            default='HEAD~1',
            help=
            'Base branch, tag, commit, or history marker to compare the current revision'
        )
        parser.add_argument('--concise',
                            '-c',
                            action='store_true',
                            help='Only display the affected uncovered lines')
        parser.add_argument('--xml',
                            '-x',
                            type=str,
                            default='coverage.xml',
                            help='Path of the generated coverage .xml')
        parser.add_argument('--repository',
                            '-r',
                            type=str,
                            default=None,
                            help='Path of the git repository')
        parser.add_argument(
            '--silently',
            '-s',
            action='store_true',
            help=
            'Even with missing coverage, exit with success system exit status')
        parser.set_defaults(concise=False)

        args = parser.parse_args()

        self._additions_finder = AdditionsFinder()
        self._coverage_processor = CoverageProcessor()
        self._base = args.base
        self._xml = args.xml
        self._repository = args.repository
        if self._repository is None:
            self._repository = getcwd()

        self._concise = args.concise
        self._silently = args.silently

    def run(self):
        try:
            additions = self._additions_finder.get_additions_for_base(
                self._base, self._repository)
            missing_coverage = self._coverage_processor.get_missing_coverage(
                additions, self._xml)

            if missing_coverage:
                visualizer = Display()
                visualizer.display_missing_coverage(missing_coverage,
                                                    self._concise)
                if not self._silently:
                    sys.exit(2)
            else:
                print('\033[32m100% relevant lines covered\033[m')
        except Exception as e:
            print("\033[31m %s\033[m" % e.message)
            sys.exit(2)
Exemplo n.º 8
0
 def setUp(self):
     self._coverage_processor = CoverageProcessor()