coala / coala-quickstart

A tool that generates an initial coala config file for you!
GNU Affero General Public License v3.0
47 stars 76 forks source link

Settings.py::get_extensions: Add tests for 100% branch coverage #279

Open jayvdb opened 6 years ago

jayvdb commented 6 years ago

This function does not have 100% branch coverage of if ext in exts:

ishanSrt commented 5 years ago

The function is present in Utilities.py not Settings.py

ishanSrt commented 5 years ago

Following that the given lines are present in setup.cfg:

[coverage:run]
branch = True

On running pytest --cov I don't see any change in branch coverage on removing that regex. Maybe this issue got removed after some merge?

ishanSrt commented 5 years ago

I don't know why, quite possible because of the changes in moban repo, I was able to recreate this today

akshatkarani commented 5 years ago

I am getting 100% test coverage :confused:

========================================================================= test session starts =========================================================================
platform linux -- Python 3.6.6, pytest-3.6.4, py-1.7.0, pluggy-0.7.1
rootdir: /home/akshat/coala-repos/coala-quickstart, inifile: setup.cfg
plugins: requests-mock-1.5.2, xdist-1.23.2, travis-fold-1.3.0, timeout-1.3.2, reqs-0.1.0, reorder-0.1.1, profiling-1.3.0, mock-1.10.0, instafail-0.3.0, forked-0.2, error-for-skips-1.0.0, env-0.6.2, cov-2.6.0
timeout: 60.0s
timeout method: signal
timeout func_only: False
collected 119 items                                                                                                                                                   

coala_quickstart/generation/Project.py .                                                                                                                        [  0%]
coala_quickstart/generation/Utilities.py .                                                                                                                      [  1%]
coala_quickstart/info_extraction/Utilities.py .                                                                                                                 [  2%]
coala_quickstart/interaction/Logo.py .                                                                                                                          [  3%]
tests/generation/BearsTest.py ........F

______________________________________________________ TestBears.test_filter_relevant_bears_with_extracted_info _______________________________________________________

self = <tests.generation.BearsTest.TestBears testMethod=test_filter_relevant_bears_with_extracted_info>

    def test_filter_relevant_bears_with_extracted_info(self):
        # results without extracted information
        languages = [('JavaScript', 70), ('Ruby', 20)]
        res_1 = filter_relevant_bears(
            languages, self.printer, self.arg_parser, {})
        for lang, _ in languages:
            self.assertIn(lang, res_1)
            self.assertTrue(len(res_1[lang]) > 0)

        # results with extracted information
        res_2 = []

        # FIXME: Create and use Test bears with
        # ``TestUtilites.bear_test_module`` instead of running
        # tests on actual bears in coala-bears package.
        with generate_files(context_filenames,
                            context_file_contents,
                            self.project_dir) as gen_files:
            extracted_info = collect_info(self.project_dir)
            res_2 = filter_relevant_bears(languages,
                                          self.printer,
                                          self.arg_parser,
                                          extracted_info)
            for lang, _ in languages:
                self.assertIn(lang, res_2)
                self.assertTrue(len(res_2[lang]) > 0)

        # Comparing both the scenarios

        # The following dict has list of bears that have their requirements
        # caputred by `ProjectDependencyInfo` from the dependency files
        # but are not part of the `IMPORTANT_BEARS_LIST` in Constants.py
        additional_bears_by_lang = {
            "JavaScript": ["ESLintBear", "HappinessLintBear"],
            "Ruby": [],
            "All": []
        }
        for lang in res_1:
            additional_bears = [bear.name for bear in res_2[lang]
                                if bear not in res_1[lang]]
            for bear in additional_bears_by_lang[lang]:
>               self.assertIn(bear, additional_bears)
E               AssertionError: 'ESLintBear' not found in ['HappinessLintBear']

tests/generation/BearsTest.py:212: AssertionError
------------------------------------------------------------------------ Captured stdout call -------------------------------------------------------------------------
What would you like the bears to detect or fix? Please select some bear capabilities using their numbers or just press 'Enter' to selectdefault capabilities (highlighted in green)
    1. Code Simplification
    2. Commented Code
    3. Complexity
    4. Documentation
    5. Duplication
    6. Formatting
    7. Grammar
    8. Memory Leak
    9. Missing Import
    10. Redundancy
    11. Security
    12. Smell
    13. Spelling
    14. Syntax
    15. Undefined Element
    16. Unreachable Code
    17. Unused Code
    18. Variable Misuse
    19. Select all default capabilities.
What would you like the bears to detect or fix? Please select some bear capabilities using their numbers or just press 'Enter' to selectdefault capabilities (highlighted in green)
    1. Code Simplification
    2. Commented Code
    3. Complexity
    4. Documentation
    5. Duplication
    6. Formatting
    7. Grammar
    8. Memory Leak
    9. Missing Import
    10. Redundancy
    11. Security
    12. Smell
    13. Spelling
    14. Syntax
    15. Undefined Element
    16. Unreachable Code
    17. Unused Code
    18. Variable Misuse
    19. Select all default capabilities.

tests/generation/BearsTest.py ....                                                                                                                              [ 14%]
tests/generation/InfoCollectorTest.py .                                                                                                                         [ 15%]
tests/generation/ProjectTest.py ....                                                                                                                            [ 18%]
tests/generation/SettingsClassTest.py ..                                                                                                                        [ 20%]
tests/generation/SettingsFillingTest.py ...........                                                                                                             [ 29%]
tests/generation/SettingsTest.py ...                                                                                                                            [ 31%]
tests/generation/UtilitiesTest.py .......................                                                                                                       [ 51%]
tests/green_mode/QuickstartBearTest.py .                                                                                                                        [ 52%]
tests/green_mode/filename_operationsTest.py ..                                                                                                                  [ 53%]
tests/green_mode/green_modeTest.py ..............................                                                                                               [ 78%]
tests/green_mode/test_dir/file_aggregatorTest.py .                                                                                                              [ 79%]
tests/info_extraction/InfoExtractorTest.py ........                                                                                                             [ 86%]
tests/info_extraction/InfoScopeTest.py ...                                                                                                                      [ 89%]
tests/info_extraction/InfoTest.py ...                                                                                                                           [ 91%]
tests/info_extractors/EditorconfigInfoExtractorTest.py .                                                                                                        [ 92%]
tests/info_extractors/GemfileInfoExtractorTest.py .                                                                                                             [ 93%]
tests/info_extractors/GruntfileInfoExtractorTest.py .                                                                                                           [ 94%]
tests/info_extractors/PackageJSONInfoExtractorTest.py ..                                                                                                        [ 95%]
tests/info_extractors/UtilitiesTest.py ..                                                                                                                       [ 97%]
tests/interaction/LogoTest.py ...                                                                                                                               [100%]
Profiling (from /home/akshat/coala-repos/coala-quickstart/prof/combined.prof):
Thu Nov  8 22:38:30 2018    /home/akshat/coala-repos/coala-quickstart/prof/combined.prof

         44194258 function calls (42515383 primitive calls) in 30.132 seconds

   Ordered by: cumulative time
   List reduced from 4387 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      119    0.000    0.000   30.159    0.253 runner.py:105(pytest_runtest_call)
      115    0.000    0.000   30.152    0.262 unittest.py:182(runtest)
      115    0.000    0.000   30.151    0.262 case.py:652(__call__)
      115    0.004    0.000   30.151    0.262 case.py:570(run)
       39    0.001    0.000   29.132    0.747 ConfigurationGathering.py:429(get_filtered_bears)
       39    0.000    0.000   29.104    0.746 ConfigurationGathering.py:409(get_all_bears)
       39    0.002    0.000   28.520    0.731 Collectors.py:403(collect_all_bears_from_sections)
       17    0.001    0.000   27.944    1.644 Bears.py:17(filter_relevant_bears)
       17    0.000    0.000   27.917    1.642 Bears.py:42(<dictcomp>)
538274/27655    1.362    0.000   24.865    0.001 decorators.py:22(yield_once_generator)
      297    0.043    0.000   24.864    0.084 Collectors.py:228(collect_bears)
    52560    0.259    0.000   24.595    0.000 Collectors.py:181(icollect_bears)
   124340    0.248    0.000   18.426    0.000 Collectors.py:27(_import_bears)
   196714    0.780    0.000   18.132    0.000 Importers.py:129(iimport_objects)
   196714    0.895    0.000   10.117    0.000 Importers.py:98(_iimport_objects)
        1    0.000    0.000    8.968    8.968 BearsTest.py:171(test_filter_relevant_bears_with_extracted_info)
        1    0.000    0.000    4.875    4.875 BearsTest.py:136(test_filter_relevant_bears_green_mode)
583658/294017    0.344    0.000    4.082    0.000 {built-in method builtins.next}
        1    0.000    0.000    3.929    3.929 BearsTest.py:126(test_filter_relevant_bears_simple)
    19879    0.049    0.000    3.854    0.000 {built-in method builtins.sorted}

----------- coverage: platform linux, python 3.6.6-final-0 -----------
Name                                                           Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------------------------------------------
coala_quickstart/Constants.py                                      7      0      0      0   100%
coala_quickstart/Strings.py                                        8      0      0      0   100%
coala_quickstart/coala_quickstart.py                              51      0      2      0   100%
coala_quickstart/generation/InfoCollector.py                      20      0      8      0   100%
coala_quickstart/generation/InfoMapping.py                         3      0      0      0   100%
coala_quickstart/generation/Project.py                            58      0     22      0   100%
coala_quickstart/generation/Settings.py                           44      0     18      0   100%
coala_quickstart/generation/SettingsClass.py                     117      0     56      0   100%
coala_quickstart/generation/SettingsFilling.py                    51      0     27      0   100%
coala_quickstart/generation/Utilities.py                         133      0     75      0   100%
coala_quickstart/generation/__init__.py                            0      0      0      0   100%
coala_quickstart/green_mode/QuickstartBear.py                     15      0      6      0   100%
coala_quickstart/green_mode/Setting.py                            14      0      8      0   100%
coala_quickstart/green_mode/file_aggregator.py                    45      0     22      0   100%
coala_quickstart/green_mode/filename_operations.py                77      0     40      0   100%
coala_quickstart/green_mode/green_mode.py                        325      0    187      0   100%
coala_quickstart/info_extraction/Info.py                          16      0      2      0   100%
coala_quickstart/info_extraction/InfoExtractor.py                 50      0     24      0   100%
coala_quickstart/info_extraction/InfoScope.py                     37      0     28      0   100%
coala_quickstart/info_extraction/Information.py                   63      0      0      0   100%
coala_quickstart/info_extraction/Utilities.py                     14      0     12      0   100%
coala_quickstart/info_extraction/__init__.py                       0      0      0      0   100%
coala_quickstart/info_extractors/PackageJSONInfoExtractor.py      27      0     10      0   100%
coala_quickstart/info_extractors/Utilities.py                     19      0     18      0   100%
coala_quickstart/info_extractors/__init__.py                       0      0      0      0   100%
coala_quickstart/interaction/Logo.py                              19      0      8      0   100%
coala_quickstart/interaction/__init__.py                           0      0      0      0   100%
----------------------------------------------------------------------------------------------------------
TOTAL                                                           1213      0    573      0   100%

Required test coverage of 100% reached. Total coverage: 100.00%
======================================================================= short test summary info =======================================================================
FAIL tests/generation/BearsTest.py::TestBears::test_filter_relevant_bears_with_extracted_info