示例#1
0
 def test_compare_univars_rounded(self):
     self.assertTrue(
         keyvalue_equals(
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             text_to_keyvalue(R_UNIVAR_ELEVATION_ROUNDED, sep="="),
             precision=0.001,
         ))
示例#2
0
 def test_single_values(self):
     keyvals = text_to_keyvalue("a: 1.5", sep=":")
     self.assertDictEqual({"a": 1.5}, keyvals)
     keyvals = text_to_keyvalue("abc=1", sep="=")
     self.assertDictEqual({"abc": 1}, keyvals)
     keyvals = text_to_keyvalue("abc=hello", sep="=")
     self.assertDictEqual({"abc": "hello"}, keyvals)
示例#3
0
 def test_single_values(self):
     keyvals = text_to_keyvalue("a: 1.5", sep=':')
     self.assertDictEqual({'a': 1.5}, keyvals)
     keyvals = text_to_keyvalue("abc=1", sep='=')
     self.assertDictEqual({'abc': 1}, keyvals)
     keyvals = text_to_keyvalue("abc=hello", sep='=')
     self.assertDictEqual({'abc': 'hello'}, keyvals)
示例#4
0
 def test_preserve_existing_raster(self):
     """Test that existing raster is preserved"""
     # TODO: write the same for other types
     # TODO: create a general functions to avoid duplication
     runivar = SimpleModule('r.univar', flags='g', map='exists')
     self.runModule(runivar, expecting_stdout=True)
     original_runivar = text_to_keyvalue(runivar.outputs.stdout,
                                         sep='=', skip_empty=True)
     module = SimpleModule('g.rename', raster=['rename_3', 'exists'], overwrite=False)
     self.assertModule(module)
     self.assertRasterExists('exists', msg="Destination (existing) map (to) should exist")
     self.assertRasterExists('rename_3', msg="Source map (from) should exist")
     runivar = SimpleModule('r.univar', flags='g', map='exists')
     self.runModule(runivar, expecting_stdout=True)
     new_runivar = text_to_keyvalue(runivar.outputs.stdout,
                                    sep='=', skip_empty=True)
     if not keyvalue_equals(dict_a=original_runivar, dict_b=new_runivar,
                            precision=1e-7):
         unused, missing, mismatch = diff_keyvalue(dict_a=original_runivar,
                                                   dict_b=new_runivar,
                                                   precision=1e-7)
         if mismatch:
             msg = "Raster map changed. It was probably overwritten.\n"
             msg += "Difference between r.univar of maps:\n"
             msg += "mismatch values"
             msg += " (key, reference, actual): %s\n" % mismatch
             self.fail(msg)
示例#5
0
 def test_preserve_existing_raster(self):
     """Test that existing raster is preserved"""
     # TODO: write the same for other types
     # TODO: create a general functions to avoid duplication
     runivar = SimpleModule('r.univar', flags='g', map='exists')
     self.runModule(runivar, expecting_stdout=True)
     original_runivar = text_to_keyvalue(runivar.outputs.stdout,
                                         sep='=',
                                         skip_empty=True)
     module = SimpleModule('g.rename',
                           raster=['rename_3', 'exists'],
                           overwrite=False)
     self.assertModule(module)
     self.assertRasterExists(
         'exists', msg="Destination (existing) map (to) should exist")
     self.assertRasterExists('rename_3',
                             msg="Source map (from) should exist")
     runivar = SimpleModule('r.univar', flags='g', map='exists')
     self.runModule(runivar, expecting_stdout=True)
     new_runivar = text_to_keyvalue(runivar.outputs.stdout,
                                    sep='=',
                                    skip_empty=True)
     if not keyvalue_equals(
             dict_a=original_runivar, dict_b=new_runivar, precision=1e-7):
         unused, missing, mismatch = diff_keyvalue(dict_a=original_runivar,
                                                   dict_b=new_runivar,
                                                   precision=1e-7)
         if mismatch:
             msg = "Raster map changed. It was probably overwritten.\n"
             msg += "Difference between r.univar of maps:\n"
             msg += "mismatch values"
             msg += " (key, reference, actual): %s\n" % mismatch
             self.fail(msg)
示例#6
0
 def test_single_values(self):
     keyvals = text_to_keyvalue("a: 1.5", sep=':')
     self.assertDictEqual({'a': 1.5}, keyvals)
     keyvals = text_to_keyvalue("abc=1", sep='=')
     self.assertDictEqual({'abc': 1}, keyvals)
     keyvals = text_to_keyvalue("abc=hello", sep='=')
     self.assertDictEqual({'abc': 'hello'}, keyvals)
示例#7
0
 def test_single_values(self):
     keyvals = text_to_keyvalue("a: 1.5", sep=":")
     self.assertDictEqual({"a": 1.5}, keyvals)
     keyvals = text_to_keyvalue("abc=1", sep="=")
     self.assertDictEqual({"abc": 1}, keyvals)
     keyvals = text_to_keyvalue("abc=hello", sep="=")
     self.assertDictEqual({"abc": "hello"}, keyvals)
示例#8
0
    def test_wrong_lines(self):
        # we consider no key-value separator as invalid line
        # and we silently ignore these
        keyvals = text_to_keyvalue("a",
                                   sep=':',
                                   skip_invalid=True,
                                   skip_empty=False)
        self.assertDictEqual({}, keyvals)

        self.assertRaises(ValueError,
                          text_to_keyvalue,
                          "a",
                          sep=':',
                          skip_invalid=False,
                          skip_empty=False)

        # text_to_keyvalue considers the empty string as valid input
        keyvals = text_to_keyvalue("",
                                   sep=':',
                                   skip_invalid=False,
                                   skip_empty=False)
        self.assertDictEqual({}, keyvals)

        self.assertRaises(ValueError,
                          text_to_keyvalue,
                          "\n",
                          sep=':',
                          skip_invalid=True,
                          skip_empty=False)

        keyvals = text_to_keyvalue("a\n\n",
                                   sep=':',
                                   skip_invalid=True,
                                   skip_empty=True)
        self.assertDictEqual({}, keyvals)
示例#9
0
 def test_compare_univars_rounded(self):
     self.assertTrue(
         keyvalue_equals(
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             text_to_keyvalue(R_UNIVAR_ELEVATION_ROUNDED, sep="="),
             precision=0.001,
         )
     )
示例#10
0
 def test_strip(self):
     keyvals = text_to_keyvalue("a:   2.8  ", sep=":")
     self.assertDictEqual({"a": 2.8}, keyvals)
     keyvals = text_to_keyvalue("a:  2  ; 2.8 ; ab cd ", sep=":", val_sep=";")
     self.assertDictEqual({"a": [2, 2.8, "ab cd"]}, keyvals)
     keyvals = text_to_keyvalue("a  :  2  ; 2.8", sep=":", val_sep=";")
     self.assertDictEqual({"a": [2, 2.8]}, keyvals)
     keyvals = text_to_keyvalue("a  : \t 2  ;\t2.8", sep=":", val_sep=";")
     self.assertDictEqual({"a": [2, 2.8]}, keyvals)
示例#11
0
 def test_strip(self):
     keyvals = text_to_keyvalue("a:   2.8  ", sep=":")
     self.assertDictEqual({"a": 2.8}, keyvals)
     keyvals = text_to_keyvalue("a:  2  ; 2.8 ; ab cd ", sep=":", val_sep=";")
     self.assertDictEqual({"a": [2, 2.8, "ab cd"]}, keyvals)
     keyvals = text_to_keyvalue("a  :  2  ; 2.8", sep=":", val_sep=";")
     self.assertDictEqual({"a": [2, 2.8]}, keyvals)
     keyvals = text_to_keyvalue("a  : \t 2  ;\t2.8", sep=":", val_sep=";")
     self.assertDictEqual({"a": [2, 2.8]}, keyvals)
示例#12
0
 def test_separators(self):
     keyvals = text_to_keyvalue("a=a;b;c", sep="=", val_sep=";")
     self.assertDictEqual({"a": ["a", "b", "c"]}, keyvals)
     keyvals = text_to_keyvalue("a 1;2;3", sep=" ", val_sep=";")
     self.assertDictEqual({"a": [1, 2, 3]}, keyvals)
     # spaces as key-value separator and values separators
     # this should work (e.g. because of : in DMS),
     # although it does not support stripping (we don't merge separators)
     keyvals = text_to_keyvalue("a 1 2 3", sep=" ", val_sep=" ")
     self.assertDictEqual({"a": [1, 2, 3]}, keyvals)
示例#13
0
 def test_separators(self):
     keyvals = text_to_keyvalue("a=a;b;c", sep='=', val_sep=';')
     self.assertDictEqual({'a': ['a', 'b', 'c']}, keyvals)
     keyvals = text_to_keyvalue("a 1;2;3", sep=' ', val_sep=';')
     self.assertDictEqual({'a': [1, 2, 3]}, keyvals)
     # spaces as key-value separator and values separators
     # this should work (e.g. because of : in DMS),
     # although it does not support stripping (we don't merge separators)
     keyvals = text_to_keyvalue("a 1 2 3", sep=' ', val_sep=' ')
     self.assertDictEqual({'a': [1, 2, 3]}, keyvals)
示例#14
0
 def test_strip(self):
     keyvals = text_to_keyvalue("a:   2.8  ", sep=':')
     self.assertDictEqual({'a': 2.8}, keyvals)
     keyvals = text_to_keyvalue("a:  2  ; 2.8 ; ab cd ",
                                sep=':', val_sep=';')
     self.assertDictEqual({'a': [2, 2.8, 'ab cd']}, keyvals)
     keyvals = text_to_keyvalue("a  :  2  ; 2.8", sep=':', val_sep=';')
     self.assertDictEqual({'a': [2, 2.8]}, keyvals)
     keyvals = text_to_keyvalue("a  : \t 2  ;\t2.8", sep=':', val_sep=';')
     self.assertDictEqual({'a': [2, 2.8]}, keyvals)
示例#15
0
 def test_separators(self):
     keyvals = text_to_keyvalue("a=a;b;c", sep='=', val_sep=';')
     self.assertDictEqual({'a': ['a', 'b', 'c']}, keyvals)
     keyvals = text_to_keyvalue("a 1;2;3", sep=' ', val_sep=';')
     self.assertDictEqual({'a': [1, 2, 3]}, keyvals)
     # spaces as key-value separator and values separators
     # this should work (e.g. because of : in DMS),
     # although it does not support stripping (we don't merge separators)
     keyvals = text_to_keyvalue("a 1 2 3", sep=' ', val_sep=' ')
     self.assertDictEqual({'a': [1, 2, 3]}, keyvals)
示例#16
0
 def test_compare_univars(self):
     self.assertTrue(
         keyvalue_equals(text_to_keyvalue(R_UNIVAR_ELEVATION, sep='='),
                         text_to_keyvalue(R_UNIVAR_ELEVATION, sep='='),
                         precision=0))
     self.assertFalse(
         keyvalue_equals(text_to_keyvalue(R_UNIVAR_ELEVATION, sep='='),
                         text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET,
                                          sep='='),
                         precision=0))
示例#17
0
 def test_strip(self):
     keyvals = text_to_keyvalue("a:   2.8  ", sep=':')
     self.assertDictEqual({'a': 2.8}, keyvals)
     keyvals = text_to_keyvalue("a:  2  ; 2.8 ; ab cd ",
                                sep=':', val_sep=';')
     self.assertDictEqual({'a': [2, 2.8, 'ab cd']}, keyvals)
     keyvals = text_to_keyvalue("a  :  2  ; 2.8", sep=':', val_sep=';')
     self.assertDictEqual({'a': [2, 2.8]}, keyvals)
     keyvals = text_to_keyvalue("a  : \t 2  ;\t2.8", sep=':', val_sep=';')
     self.assertDictEqual({'a': [2, 2.8]}, keyvals)
示例#18
0
 def test_separators(self):
     keyvals = text_to_keyvalue("a=a;b;c", sep="=", val_sep=";")
     self.assertDictEqual({"a": ["a", "b", "c"]}, keyvals)
     keyvals = text_to_keyvalue("a 1;2;3", sep=" ", val_sep=";")
     self.assertDictEqual({"a": [1, 2, 3]}, keyvals)
     # spaces as key-value separator and values separators
     # this should work (e.g. because of : in DMS),
     # although it does not support stripping (we don't merge separators)
     keyvals = text_to_keyvalue("a 1 2 3", sep=" ", val_sep=" ")
     self.assertDictEqual({"a": [1, 2, 3]}, keyvals)
示例#19
0
 def test_compare_univars_subset(self):
     self.assertTrue(keyvalue_equals(text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET,
                                                       sep='='),
                                      text_to_keyvalue(R_UNIVAR_ELEVATION,
                                                       sep='='),
                                      a_is_subset=True, precision=0))
     self.assertFalse(keyvalue_equals(text_to_keyvalue(R_UNIVAR_ELEVATION,
                                                        sep='='),
                                       text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET,
                                                        sep='='),
                                       a_is_subset=True, precision=0))
示例#20
0
 def test_compare_univars_subset(self):
     self.assertTrue(
         keyvalue_equals(
             text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET, sep="="),
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             a_is_subset=True,
             precision=0,
         ))
     self.assertFalse(
         keyvalue_equals(
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET, sep="="),
             a_is_subset=True,
             precision=0,
         ))
示例#21
0
 def test_compare_univars(self):
     self.assertTrue(
         keyvalue_equals(
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             precision=0,
         )
     )
     self.assertFalse(
         keyvalue_equals(
             text_to_keyvalue(R_UNIVAR_ELEVATION, sep="="),
             text_to_keyvalue(R_UNIVAR_ELEVATION_SUBSET, sep="="),
             precision=0,
         )
     )
示例#22
0
    def test_overwrite_existing_raster(self):
        """Test that existing raster is overriden if desired"""
        runivar_source = SimpleModule('r.univar', flags='g', map='rename_3')
        self.runModule(runivar_source, expecting_stdout=True)
        original_runivar_source = text_to_keyvalue(
            runivar_source.outputs.stdout, sep='=', skip_empty=True)
        runivar_target = SimpleModule('r.univar', flags='g', map='exists')
        self.runModule(runivar_target, expecting_stdout=True)
        original_runivar_target = text_to_keyvalue(
            runivar_target.outputs.stdout, sep='=', skip_empty=True)
        module = SimpleModule('g.rename',
                              raster=['rename_3', 'exists'],
                              overwrite=True)
        self.assertModule(module)
        self.assertRasterExists(
            'exists',
            msg=
            "Destination (here: existing) map (to) should exist after rename")
        self.assertFalse(is_map_in_mapset('rename_3', type='raster'),
                         msg="Source map (from) should not exist after rename")

        runivar = SimpleModule('r.univar', flags='g', map='exists')
        self.runModule(runivar, expecting_stdout=True)
        new_runivar = text_to_keyvalue(runivar.outputs.stdout,
                                       sep='=',
                                       skip_empty=True)

        # both these tests are probably redundant but let's test thoroughly
        if keyvalue_equals(dict_a=original_runivar_target,
                           dict_b=new_runivar,
                           precision=1e-7):
            msg = "Raster map did not change. It probably wasn't overwritten."
            self.fail(msg)

        if not keyvalue_equals(dict_a=original_runivar_source,
                               dict_b=new_runivar,
                               precision=1e-7):
            unused, missing, mismatch = diff_keyvalue(
                dict_a=original_runivar_source,
                dict_b=new_runivar,
                precision=1e-7)
            if mismatch:
                msg = "Destination raster map is not the same as source."
                msg += " It probably wasn't overwritten.\n"
                msg += "Difference between r.univar of maps:\n"
                msg += "mismatch values"
                msg += " (key, reference, actual): %s\n" % mismatch
                self.fail(msg)
示例#23
0
    def test_wrong_lines(self):
        # we consider no key-value separator as invalid line
        # and we silently ignore these
        keyvals = text_to_keyvalue("a", sep=":", skip_invalid=True, skip_empty=False)
        self.assertDictEqual({}, keyvals)

        self.assertRaises(ValueError, text_to_keyvalue, "a", sep=":", skip_invalid=False, skip_empty=False)

        # text_to_keyvalue considers the empty string as valid input
        keyvals = text_to_keyvalue("", sep=":", skip_invalid=False, skip_empty=False)
        self.assertDictEqual({}, keyvals)

        self.assertRaises(ValueError, text_to_keyvalue, "\n", sep=":", skip_invalid=True, skip_empty=False)

        keyvals = text_to_keyvalue("a\n\n", sep=":", skip_invalid=True, skip_empty=True)
        self.assertDictEqual({}, keyvals)
示例#24
0
 def test_conversion(self):
     keyvals = text_to_keyvalue(KEYVAL_TEXT, sep=':', val_sep=',')
     expected = {'s': 'Hello',
                 'str': 'Hello world!',
                 'f': 1.0,
                 'l': [1, 2, 3, 4, 5],
                 'mixed': ['hello', 8, -25, 'world!',
                           '4-1', '5:2', 0.1, -9.6]}
     self.assertDictEqual(expected, keyvals)
示例#25
0
 def test_conversion(self):
     keyvals = text_to_keyvalue(KEYVAL_TEXT, sep=':', val_sep=',')
     expected = {'s': 'Hello',
                 'str': 'Hello world!',
                 'f': 1.0,
                 'l': [1, 2, 3, 4, 5],
                 'mixed': ['hello', 8, -25, 'world!',
                           '4-1', '5:2', 0.1, -9.6]}
     self.assertDictEqual(expected, keyvals)
示例#26
0
 def test_conversion(self):
     keyvals = text_to_keyvalue(KEYVAL_TEXT, sep=":", val_sep=",")
     expected = {
         "s": "Hello",
         "str": "Hello world!",
         "f": 1.0,
         "l": [1, 2, 3, 4, 5],
         "mixed": ["hello", 8, -25, "world!", "4-1", "5:2", 0.1, -9.6],
     }
     self.assertDictEqual(expected, keyvals)
示例#27
0
 def test_conversion(self):
     keyvals = text_to_keyvalue(KEYVAL_TEXT, sep=":", val_sep=",")
     expected = {
         "s": "Hello",
         "str": "Hello world!",
         "f": 1.0,
         "l": [1, 2, 3, 4, 5],
         "mixed": ["hello", 8, -25, "world!", "4-1", "5:2", 0.1, -9.6],
     }
     self.assertDictEqual(expected, keyvals)
示例#28
0
    def test_overwrite_existing_raster(self):
        """Test that existing raster is overriden if desired"""
        runivar_source = SimpleModule('r.univar', flags='g', map='rename_3')
        self.runModule(runivar_source, expecting_stdout=True)
        original_runivar_source = text_to_keyvalue(runivar_source.outputs.stdout,
                                                   sep='=', skip_empty=True)
        runivar_target = SimpleModule('r.univar', flags='g', map='exists')
        self.runModule(runivar_target, expecting_stdout=True)
        original_runivar_target = text_to_keyvalue(runivar_target.outputs.stdout,
                                                   sep='=', skip_empty=True)
        module = SimpleModule('g.rename', raster=['rename_3', 'exists'], overwrite=True)
        self.assertModule(module)
        self.assertRasterExists('exists', msg="Destination (here: existing) map (to) should exist after rename")
        self.assertFalse(is_map_in_mapset('rename_3', type='raster'),
                         msg="Source map (from) should not exist after rename")

        runivar = SimpleModule('r.univar', flags='g', map='exists')
        self.runModule(runivar, expecting_stdout=True)
        new_runivar = text_to_keyvalue(runivar.outputs.stdout,
                                       sep='=', skip_empty=True)

        # both these tests are probably redundant but let's test thoroughly
        if keyvalue_equals(dict_a=original_runivar_target, dict_b=new_runivar,
                           precision=1e-7):
            msg = "Raster map did not change. It probably wasn't overwritten."
            self.fail(msg)

        if not keyvalue_equals(dict_a=original_runivar_source, dict_b=new_runivar,
                               precision=1e-7):
            unused, missing, mismatch = diff_keyvalue(dict_a=original_runivar_source,
                                                      dict_b=new_runivar,
                                                      precision=1e-7)
            if mismatch:
                msg = "Destination raster map is not the same as source."
                msg += " It probably wasn't overwritten.\n"
                msg += "Difference between r.univar of maps:\n"
                msg += "mismatch values"
                msg += " (key, reference, actual): %s\n" % mismatch
                self.fail(msg)
示例#29
0
def main():

    parser = argparse.ArgumentParser(
        description="Create overall report from several individual test reports"
    )
    parser.add_argument(
        "reports",
        metavar="report_directory",
        type=str,
        nargs="+",
        help="Directories with reports",
    )
    parser.add_argument(
        "--output",
        dest="output",
        action="store",
        default="testreports_summary",
        help="Output directory",
    )
    parser.add_argument(
        "--timestamps",
        dest="timestamps",
        action="store_true",
        help="Use file timestamp instead of date in test summary",
    )

    args = parser.parse_args()
    output = args.output
    reports = args.reports
    use_timestamps = args.timestamps

    ensure_dir(output)

    all_results = []
    results_in_locations = defaultdict(list)

    for report in reports:
        try:
            summary_file = os.path.join(report, "test_keyvalue_result.txt")
            if not os.path.exists(summary_file):
                sys.stderr.write("WARNING: Key-value summary not available in"
                                 " report <%s>, skipping.\n" % summary_file)
                # skipping incomplete reports
                # use only results list for further processing
                continue
            summary = text_to_keyvalue(open(summary_file).read(), sep="=")
            if use_timestamps:
                test_timestamp = datetime.datetime.fromtimestamp(
                    os.path.getmtime(summary_file))
            else:
                test_timestamp = datetime.datetime.strptime(
                    summary["timestamp"], "%Y-%m-%d %H:%M:%S")

            result = TestResultSummary()
            result.timestamp = test_timestamp
            result.total = summary["total"]
            result.successes = summary["successes"]
            result.failures = summary["failures"]
            result.errors = summary["errors"]

            result.files_total = summary["files_total"]
            result.files_successes = summary["files_successes"]
            result.files_failures = summary["files_failures"]

            result.svn_revision = str(summary["svn_revision"])
            result.tested_modules = summary["tested_modules"]
            result.names = summary["names"]
            result.test_files_authors = summary["test_files_authors"]
            result.tested_dirs = summary["tested_dirs"]
            result.report = report

            # let's consider no location as valid state and use 'unknown'
            result.location = summary.get("location", "unknown")
            result.location_type = summary.get("location_type", "unknown")
            # grouping according to location types
            # this can cause that two actual locations tested at the same time
            # will end up together, this is not ideal but testing with
            # one location type and different actual locations is not standard
            # and although it will not break anything it will not give a nice
            # report
            results_in_locations[result.location_type].append(result)

            all_results.append(result)
            del result
        except KeyError as e:
            print("File %s does not have right values (%s)" %
                  (report, e.message))

    locations_main_page = open(os.path.join(output, "index.html"), "w")
    locations_main_page.write(
        "<html><body>"
        "<h1>Test reports grouped by location type</h1>"
        "<table>"
        "<thead><tr>"
        "<th>Location</th>"
        "<th>Successful files</th><th>Successful tests</th>"
        "</tr></thead>"
        "<tbody>")

    PlotStyle = namedtuple(
        "PlotStyle",
        [
            "linestyle", "linewidth", "success_color", "fail_color",
            "total_color"
        ],
    )
    plot_style = PlotStyle(linestyle="-",
                           linewidth=4.0,
                           success_color="g",
                           fail_color="r",
                           total_color="b")

    for location_type, results in results_in_locations.items():
        results = sorted(results, key=operator.attrgetter("timestamp"))
        # TODO: document: location type must be a valid dir name
        directory = os.path.join(output, location_type)
        ensure_dir(directory)

        if location_type == "unknown":
            title = "Test reports"
        else:
            title = "Test reports for &lt;{type}&gt; location type".format(
                type=location_type)

        x = [date2num(result.timestamp) for result in results]
        # the following would be an alternative but it does not work with
        # labels and automatic axis limits even after removing another date fun
        # x = [result.svn_revision for result in results]
        xlabels = [
            result.timestamp.strftime("%Y-%m-%d") + " (r" +
            result.svn_revision + ")" for result in results
        ]
        step = len(x) / 10
        xticks = x[step::step]
        xlabels = xlabels[step::step]
        tests_successful_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "tests_successful_plot.png"),
            style=plot_style,
        )
        files_successful_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "files_successful_plot.png"),
            style=plot_style,
        )
        tests_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "tests_plot.png"),
            style=plot_style,
        )
        tests_percent_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "tests_percent_plot.png"),
            style=plot_style,
        )
        files_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "files_plot.png"),
            style=plot_style,
        )
        files_percent_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "files_percent_plot.png"),
            style=plot_style,
        )
        info_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "info_plot.png"),
            style=plot_style,
        )

        main_page(
            results=results,
            filename="index.html",
            images=[
                "tests_successful_plot.png",
                "files_successful_plot.png",
                "tests_plot.png",
                "files_plot.png",
                "tests_percent_plot.png",
                "files_percent_plot.png",
                "info_plot.png",
            ],
            captions=[
                "Success of individual tests in percents",
                "Success of test files in percents",
                "Successes, failures and number of individual tests",
                "Successes, failures and number of test files",
                "Successes and failures of individual tests in percent",
                "Successes and failures of test files in percents",
                "Additional information",
            ],
            directory=directory,
            title=title,
        )

        files_successes = sum(result.files_successes for result in results)
        files_total = sum(result.files_total for result in results)
        successes = sum(result.successes for result in results)
        total = sum(result.total for result in results)
        per_test = success_to_html_percent(total=total, successes=successes)
        per_file = success_to_html_percent(total=files_total,
                                           successes=files_successes)
        locations_main_page.write(
            "<tr>"
            "<td><a href={location}/index.html>{location}</a></td>"
            "<td>{pfiles}</td><td>{ptests}</td>"
            "</tr>".format(location=location_type,
                           pfiles=per_file,
                           ptests=per_test))
    locations_main_page.write("</tbody></table>")
    locations_main_page.write("</body></html>")
    locations_main_page.close()
    return 0
示例#30
0
 def test_empty_value(self):
     keyvals = text_to_keyvalue("a: ", sep=':')
     self.assertDictEqual({'a': ''}, keyvals)
     keyvals = text_to_keyvalue("a:", sep=':')
     self.assertDictEqual({'a': ''}, keyvals)
示例#31
0
 def test_empty_list_item(self):
     keyvals = text_to_keyvalue("a: 1, ,5,,", sep=":", val_sep=",")
     self.assertDictEqual({"a": [1, "", 5, "", ""]}, keyvals)
示例#32
0
 def test_empty_value(self):
     keyvals = text_to_keyvalue("a: ", sep=":")
     self.assertDictEqual({"a": ""}, keyvals)
     keyvals = text_to_keyvalue("a:", sep=":")
     self.assertDictEqual({"a": ""}, keyvals)
示例#33
0
def main():

    parser = argparse.ArgumentParser(
        description='Create overall report from several individual test reports'
    )
    parser.add_argument('reports',
                        metavar='report_directory',
                        type=str,
                        nargs='+',
                        help='Directories with reports')
    parser.add_argument('--output',
                        dest='output',
                        action='store',
                        default='testreports_summary',
                        help='Output directory')
    parser.add_argument(
        '--timestamps',
        dest='timestamps',
        action='store_true',
        help='Use file timestamp instead of date in test summary')

    args = parser.parse_args()
    output = args.output
    reports = args.reports
    use_timestamps = args.timestamps

    ensure_dir(output)

    all_results = []
    results_in_locations = defaultdict(list)

    for report in reports:
        try:
            summary_file = os.path.join(report, 'test_keyvalue_result.txt')
            if not os.path.exists(summary_file):
                sys.stderr.write('WARNING: Key-value summary not available in'
                                 ' report <%s>, skipping.\n' % summary_file)
                # skipping incomplete reports
                # use only results list for further processing
                continue
            summary = text_to_keyvalue(open(summary_file).read(), sep='=')
            if use_timestamps:
                test_timestamp = datetime.datetime.fromtimestamp(
                    os.path.getmtime(summary_file))
            else:
                test_timestamp = datetime.datetime.strptime(
                    summary['timestamp'], "%Y-%m-%d %H:%M:%S")

            result = TestResultSummary()
            result.timestamp = test_timestamp
            result.total = summary['total']
            result.successes = summary['successes']
            result.failures = summary['failures']
            result.errors = summary['errors']

            result.files_total = summary['files_total']
            result.files_successes = summary['files_successes']
            result.files_failures = summary['files_failures']

            result.svn_revision = str(summary['svn_revision'])
            result.tested_modules = summary['tested_modules']
            result.names = summary['names']
            result.test_files_authors = summary['test_files_authors']
            result.tested_dirs = summary['tested_dirs']
            result.report = report

            # let's consider no location as valid state and use 'unknown'
            result.location = summary.get('location', 'unknown')
            result.location_type = summary.get('location_type', 'unknown')
            # grouping according to location types
            # this can cause that two actual locations tested at the same time
            # will end up together, this is not ideal but testing with
            # one location type and different actual locations is not standard
            # and although it will not break anything it will not give a nice
            # report
            results_in_locations[result.location_type].append(result)

            all_results.append(result)
            del result
        except KeyError as e:
            print('File %s does not have right values (%s)' %
                  (report, e.message))

    locations_main_page = open(os.path.join(output, 'index.html'), 'w')
    locations_main_page.write(
        '<html><body>'
        '<h1>Test reports grouped by location type</h1>'
        '<table>'
        '<thead><tr>'
        '<th>Location</th>'
        '<th>Successful files</th><th>Successful tests</th>'
        '</tr></thead>'
        '<tbody>')

    PlotStyle = namedtuple('PlotStyle', [
        'linestyle', 'linewidth', 'success_color', 'fail_color', 'total_color'
    ])
    plot_style = PlotStyle(linestyle='-',
                           linewidth=4.0,
                           success_color='g',
                           fail_color='r',
                           total_color='b')

    for location_type, results in results_in_locations.items():
        results = sorted(results, key=operator.attrgetter('timestamp'))
        # TODO: document: location type must be a valid dir name
        directory = os.path.join(output, location_type)
        ensure_dir(directory)

        if location_type == 'unknown':
            title = 'Test reports'
        else:
            title = ('Test reports for &lt;{type}&gt; location type'.format(
                type=location_type))

        x = [date2num(result.timestamp) for result in results]
        # the following would be an alternative but it does not work with
        # labels and automatic axis limits even after removing another date fun
        # x = [result.svn_revision for result in results]
        xlabels = [
            result.timestamp.strftime("%Y-%m-%d") + ' (r' +
            result.svn_revision + ')' for result in results
        ]
        step = len(x) / 10
        xticks = x[step::step]
        xlabels = xlabels[step::step]
        tests_successful_plot(x=x,
                              xticks=xticks,
                              xlabels=xlabels,
                              results=results,
                              filename=os.path.join(
                                  directory, 'tests_successful_plot.png'),
                              style=plot_style)
        files_successful_plot(x=x,
                              xticks=xticks,
                              xlabels=xlabels,
                              results=results,
                              filename=os.path.join(
                                  directory, 'files_successful_plot.png'),
                              style=plot_style)
        tests_plot(x=x,
                   xticks=xticks,
                   xlabels=xlabels,
                   results=results,
                   filename=os.path.join(directory, 'tests_plot.png'),
                   style=plot_style)
        tests_percent_plot(x=x,
                           xticks=xticks,
                           xlabels=xlabels,
                           results=results,
                           filename=os.path.join(directory,
                                                 'tests_percent_plot.png'),
                           style=plot_style)
        files_plot(x=x,
                   xticks=xticks,
                   xlabels=xlabels,
                   results=results,
                   filename=os.path.join(directory, 'files_plot.png'),
                   style=plot_style)
        files_percent_plot(x=x,
                           xticks=xticks,
                           xlabels=xlabels,
                           results=results,
                           filename=os.path.join(directory,
                                                 'files_percent_plot.png'),
                           style=plot_style)
        info_plot(x=x,
                  xticks=xticks,
                  xlabels=xlabels,
                  results=results,
                  filename=os.path.join(directory, 'info_plot.png'),
                  style=plot_style)

        main_page(results=results,
                  filename='index.html',
                  images=[
                      'tests_successful_plot.png', 'files_successful_plot.png',
                      'tests_plot.png', 'files_plot.png',
                      'tests_percent_plot.png', 'files_percent_plot.png',
                      'info_plot.png'
                  ],
                  captions=[
                      'Success of individual tests in percents',
                      'Success of test files in percents',
                      'Successes, failures and number of individual tests',
                      'Successes, failures and number of test files',
                      'Successes and failures of individual tests in percent',
                      'Successes and failures of test files in percents',
                      'Additional information'
                  ],
                  directory=directory,
                  title=title)

        files_successes = sum(result.files_successes for result in results)
        files_total = sum(result.files_total for result in results)
        successes = sum(result.successes for result in results)
        total = sum(result.total for result in results)
        per_test = success_to_html_percent(total=total, successes=successes)
        per_file = success_to_html_percent(total=files_total,
                                           successes=files_successes)
        locations_main_page.write(
            '<tr>'
            '<td><a href={location}/index.html>{location}</a></td>'
            '<td>{pfiles}</td><td>{ptests}</td>'
            '</tr>'.format(location=location_type,
                           pfiles=per_file,
                           ptests=per_test))
    locations_main_page.write('</tbody></table>')
    locations_main_page.write('</body></html>')
    locations_main_page.close()
    return 0
示例#34
0
 def test_empty_list_item(self):
     keyvals = text_to_keyvalue("a: 1, ,5,,", sep=":", val_sep=",")
     self.assertDictEqual({"a": [1, "", 5, "", ""]}, keyvals)
示例#35
0
 def test_empty_value(self):
     keyvals = text_to_keyvalue("a: ", sep=":")
     self.assertDictEqual({"a": ""}, keyvals)
     keyvals = text_to_keyvalue("a:", sep=":")
     self.assertDictEqual({"a": ""}, keyvals)
示例#36
0
 def test_empty_list_item(self):
     keyvals = text_to_keyvalue("a: 1, ,5,,", sep=':', val_sep=',')
     self.assertDictEqual({'a': [1, '', 5, '', '']}, keyvals)
示例#37
0
 def test_empty_value(self):
     keyvals = text_to_keyvalue("a: ", sep=':')
     self.assertDictEqual({'a': ''}, keyvals)
     keyvals = text_to_keyvalue("a:", sep=':')
     self.assertDictEqual({'a': ''}, keyvals)
示例#38
0
 def test_empty_list_item(self):
     keyvals = text_to_keyvalue("a: 1, ,5,,", sep=':', val_sep=',')
     self.assertDictEqual({'a': [1, '', 5, '', '']}, keyvals)
示例#39
0
def main():

    parser = argparse.ArgumentParser(
        description='Create overall report from several individual test reports')
    parser.add_argument('reports', metavar='report_directory',
                        type=str, nargs='+',
                        help='Directories with reports')
    parser.add_argument('--output', dest='output', action='store',
                        default='testreports_summary',
                        help='Output directory')
    parser.add_argument('--timestamps', dest='timestamps', action='store_true',
                        help='Use file timestamp instead of date in test summary')

    args = parser.parse_args()
    output = args.output
    reports = args.reports
    use_timestamps = args.timestamps

    ensure_dir(output)

    all_results = []
    results_in_locations = defaultdict(list)

    for report in reports:
        try:
            summary_file = os.path.join(report, 'test_keyvalue_result.txt')
            if not os.path.exists(summary_file):
                sys.stderr.write('WARNING: Key-value summary not available in'
                                 ' report <%s>, skipping.\n' % summary_file)
                # skipping incomplete reports
                # use only results list for further processing
                continue
            summary = text_to_keyvalue(open(summary_file).read(), sep='=')
            if use_timestamps:
                test_timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(summary_file))
            else:
                test_timestamp = datetime.datetime.strptime(summary['timestamp'], "%Y-%m-%d %H:%M:%S")

            result = TestResultSummary()
            result.timestamp = test_timestamp
            result.total = summary['total']
            result.successes = summary['successes']
            result.failures = summary['failures']
            result.errors = summary['errors']

            result.files_total = summary['files_total']
            result.files_successes = summary['files_successes']
            result.files_failures = summary['files_failures']

            result.svn_revision = str(summary['svn_revision'])
            result.tested_modules = summary['tested_modules']
            result.names = summary['names']
            result.test_files_authors = summary['test_files_authors']
            result.tested_dirs = summary['tested_dirs']
            result.report = report

            # let's consider no location as valid state and use 'unknown'
            result.location = summary.get('location', 'unknown')
            result.location_type = summary.get('location_type', 'unknown')
            # grouping according to location types
            # this can cause that two actual locations tested at the same time
            # will end up together, this is not ideal but testing with
            # one location type and different actual locations is not standard
            # and although it will not break anything it will not give a nice
            # report
            results_in_locations[result.location_type].append(result)

            all_results.append(result)
            del result
        except KeyError as e:
            print 'File %s does not have right values (%s)' % (report, e.message) 

    locations_main_page = open(os.path.join(output, 'index.html'), 'w')
    locations_main_page.write(
        '<html><body>'
        '<h1>Test reports grouped by location type</h1>'
        '<table>'
        '<thead><tr>'
        '<th>Location</th>'
        '<th>Successful files</th><th>Successful tests</th>'
        '</tr></thead>'
        '<tbody>'
        )

    PlotStyle = namedtuple('PlotStyle',
                           ['linestyle', 'linewidth',
                           'success_color', 'fail_color', 'total_color'])
    plot_style = PlotStyle(linestyle='-', linewidth=4.0,
                           success_color='g', fail_color='r', total_color='b')

    for location_type, results in results_in_locations.iteritems():
        results = sorted(results, key=operator.attrgetter('timestamp'))
        # TODO: document: location type must be a valid dir name
        directory = os.path.join(output, location_type)
        ensure_dir(directory)

        if location_type == 'unknown':
            title = 'Test reports'
        else:
            title = ('Test reports for &lt;{type}&gt; location type'
                     .format(type=location_type))
        
        x = [date2num(result.timestamp) for result in results]
        # the following would be an alternative but it does not work with
        # labels and automatic axis limits even after removing another date fun
        # x = [result.svn_revision for result in results]
        xlabels = [result.timestamp.strftime("%Y-%m-%d") + ' (r' + result.svn_revision + ')' for result in results]
        step = len(x) / 10
        xticks = x[step::step]
        xlabels = xlabels[step::step]
        tests_successful_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                              filename=os.path.join(directory, 'tests_successful_plot.png'),
                              style=plot_style)
        files_successful_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                              filename=os.path.join(directory, 'files_successful_plot.png'),
                              style=plot_style)
        tests_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                   filename=os.path.join(directory, 'tests_plot.png'),
                   style=plot_style)
        tests_percent_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                           filename=os.path.join(directory, 'tests_percent_plot.png'),
                           style=plot_style)
        files_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                   filename=os.path.join(directory, 'files_plot.png'),
                   style=plot_style)
        files_percent_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                           filename=os.path.join(directory, 'files_percent_plot.png'),
                           style=plot_style)
        info_plot(x=x, xticks=xticks, xlabels=xlabels, results=results,
                  filename=os.path.join(directory, 'info_plot.png'),
                   style=plot_style)

        main_page(results=results, filename='index.html',
                  images=['tests_successful_plot.png',
                          'files_successful_plot.png',
                          'tests_plot.png',
                          'files_plot.png',
                          'tests_percent_plot.png',
                          'files_percent_plot.png',
                          'info_plot.png'],
                  captions=['Success of individual tests in percents',
                            'Success of test files in percents',
                            'Successes, failures and number of individual tests',
                            'Successes, failures and number of test files',
                            'Successes and failures of individual tests in percent',
                            'Successes and failures of test files in percents',
                            'Additional information'],
                  directory=directory,
                  title=title)

        files_successes = sum(result.files_successes for result in results)
        files_total = sum(result.files_total for result in results)
        successes = sum(result.successes for result in results)
        total = sum(result.total for result in results)
        per_test = success_to_html_percent(
            total=total, successes=successes)
        per_file = success_to_html_percent(
            total=files_total, successes=files_successes)
        locations_main_page.write(
            '<tr>'
            '<td><a href={location}/index.html>{location}</a></td>'
            '<td>{pfiles}</td><td>{ptests}</td>'
            '</tr>'
            .format(location=location_type,
                    pfiles=per_file, ptests=per_test))
    locations_main_page.write('</tbody></table>')
    locations_main_page.write('</body></html>')
    locations_main_page.close()
    return 0
示例#40
0
def main():

    parser = argparse.ArgumentParser(description="Create overall report from several individual test reports")
    parser.add_argument("reports", metavar="report_directory", type=str, nargs="+", help="Directories with reports")
    parser.add_argument(
        "--output", dest="output", action="store", default="testreports_summary", help="Output directory"
    )
    parser.add_argument(
        "--timestamps",
        dest="timestamps",
        action="store_true",
        help="Use file timestamp instead of date in test summary",
    )

    args = parser.parse_args()
    output = args.output
    reports = args.reports
    use_timestamps = args.timestamps

    ensure_dir(output)

    all_results = []
    results_in_locations = defaultdict(list)

    for report in reports:
        try:
            summary_file = os.path.join(report, "test_keyvalue_result.txt")
            if not os.path.exists(summary_file):
                sys.stderr.write(
                    "WARNING: Key-value summary not available in" " report <%s>, skipping.\n" % summary_file
                )
                # skipping incomplete reports
                # use only results list for further processing
                continue
            summary = text_to_keyvalue(open(summary_file).read(), sep="=")
            if use_timestamps:
                test_timestamp = datetime.datetime.fromtimestamp(os.path.getmtime(summary_file))
            else:
                test_timestamp = datetime.datetime.strptime(summary["timestamp"], "%Y-%m-%d %H:%M:%S")

            result = TestResultSummary()
            result.timestamp = test_timestamp
            result.total = summary["total"]
            result.successes = summary["successes"]
            result.failures = summary["failures"]
            result.errors = summary["errors"]

            result.files_total = summary["files_total"]
            result.files_successes = summary["files_successes"]
            result.files_failures = summary["files_failures"]

            result.svn_revision = str(summary["svn_revision"])
            result.tested_modules = summary["tested_modules"]
            result.names = summary["names"]
            result.test_files_authors = summary["test_files_authors"]
            result.tested_dirs = summary["tested_dirs"]
            result.report = report

            # let's consider no location as valid state and use 'unknown'
            result.location = summary.get("location", "unknown")
            result.location_type = summary.get("location_type", "unknown")
            # grouping according to location types
            # this can cause that two actual locations tested at the same time
            # will end up together, this is not ideal but testing with
            # one location type and different actual locations is not standard
            # and although it will not break anything it will not give a nice
            # report
            results_in_locations[result.location_type].append(result)

            all_results.append(result)
            del result
        except KeyError as e:
            print("File %s does not have right values (%s)" % (report, e.message))

    locations_main_page = open(os.path.join(output, "index.html"), "w")
    locations_main_page.write(
        "<html><body>"
        "<h1>Test reports grouped by location type</h1>"
        "<table>"
        "<thead><tr>"
        "<th>Location</th>"
        "<th>Successful files</th><th>Successful tests</th>"
        "</tr></thead>"
        "<tbody>"
    )

    PlotStyle = namedtuple("PlotStyle", ["linestyle", "linewidth", "success_color", "fail_color", "total_color"])
    plot_style = PlotStyle(linestyle="-", linewidth=4.0, success_color="g", fail_color="r", total_color="b")

    for location_type, results in results_in_locations.items():
        results = sorted(results, key=operator.attrgetter("timestamp"))
        # TODO: document: location type must be a valid dir name
        directory = os.path.join(output, location_type)
        ensure_dir(directory)

        if location_type == "unknown":
            title = "Test reports"
        else:
            title = "Test reports for &lt;{type}&gt; location type".format(type=location_type)

        x = [date2num(result.timestamp) for result in results]
        # the following would be an alternative but it does not work with
        # labels and automatic axis limits even after removing another date fun
        # x = [result.svn_revision for result in results]
        xlabels = [result.timestamp.strftime("%Y-%m-%d") + " (r" + result.svn_revision + ")" for result in results]
        step = len(x) / 10
        xticks = x[step::step]
        xlabels = xlabels[step::step]
        tests_successful_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "tests_successful_plot.png"),
            style=plot_style,
        )
        files_successful_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "files_successful_plot.png"),
            style=plot_style,
        )
        tests_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "tests_plot.png"),
            style=plot_style,
        )
        tests_percent_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "tests_percent_plot.png"),
            style=plot_style,
        )
        files_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "files_plot.png"),
            style=plot_style,
        )
        files_percent_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "files_percent_plot.png"),
            style=plot_style,
        )
        info_plot(
            x=x,
            xticks=xticks,
            xlabels=xlabels,
            results=results,
            filename=os.path.join(directory, "info_plot.png"),
            style=plot_style,
        )

        main_page(
            results=results,
            filename="index.html",
            images=[
                "tests_successful_plot.png",
                "files_successful_plot.png",
                "tests_plot.png",
                "files_plot.png",
                "tests_percent_plot.png",
                "files_percent_plot.png",
                "info_plot.png",
            ],
            captions=[
                "Success of individual tests in percents",
                "Success of test files in percents",
                "Successes, failures and number of individual tests",
                "Successes, failures and number of test files",
                "Successes and failures of individual tests in percent",
                "Successes and failures of test files in percents",
                "Additional information",
            ],
            directory=directory,
            title=title,
        )

        files_successes = sum(result.files_successes for result in results)
        files_total = sum(result.files_total for result in results)
        successes = sum(result.successes for result in results)
        total = sum(result.total for result in results)
        per_test = success_to_html_percent(total=total, successes=successes)
        per_file = success_to_html_percent(total=files_total, successes=files_successes)
        locations_main_page.write(
            "<tr>"
            "<td><a href={location}/index.html>{location}</a></td>"
            "<td>{pfiles}</td><td>{ptests}</td>"
            "</tr>".format(location=location_type, pfiles=per_file, ptests=per_test)
        )
    locations_main_page.write("</tbody></table>")
    locations_main_page.write("</body></html>")
    locations_main_page.close()
    return 0