示例#1
0
 def to_string(self, encoding=None, indent=True, use_default_ns=True):
     """Convert this Elements object to XML string"""
     
     etree = self.to_elementtree()
     if indent:
         util.indent(etree)
     if use_default_ns:
         util.use_default_ns(etree)
     return ET.tostring(element=etree, encoding=encoding)
示例#2
0
    def pretty(self):
        pretty_body = prettify_lines(self.body)

        bar = '│'

        text = '\n'.join([
            indent(f' {self.assumption.pretty}', bar),
            '├───',
            indent(pretty_body, bar),
        ])
        return text
def run_tests(collection1, collection2, names):
    okay = True
    for name in names:
        this_file = __file__[__file__.rfind('/') + 1:].replace('.pyc', '.py')
        if name.endswith('_tests.py') and name != this_file:
            print "\nRunning tests from module \"%s\"" % util.alert(
                name[:-3], 'okblue')
            m = importlib.import_module('unit.' + name[:-3])
            passed = m.test_all(collection1, collection2)
            okay = passed and okay
            print util.indent(util.alert("%s tests" % str(len(m.tests))), 1)
            print "end of \"%s\"" % util.alert(name[:-3],
                                               'okgreen' if passed else 'fail')
    return okay
示例#4
0
 def __str__(self):
     text = '\n'.join([
         'assuming ' +
         str(self.assumption) if self.assumption else 'no assumption',
         *map(str, self.body),
     ])
     return indent(text, '| ')
示例#5
0
def format_actual_failures(failure_dict, known_failures, verbosity):
    rv = ""
    for category in 'New Failures', 'Known Failures, Unknown Error', 'Known Failures':
        rv += indent(str(category), width=4) + '\n'
        category_failures = failure_dict[category]

        if verbosity > 1 or category != 'Known Failures':
            if category_failures:
                for f in category_failures:
                    rv += indent(pasteable_name(f).strip(), width=8) + '\n'

                    jira_urls = tuple('(see {})'.format(mf.jira_url)
                                      for mf in matching_failures(f, known_failures))
                    if jira_urls:
                        rv += indent('\n'.join(jira_urls), width=8) + '\n'
                    elif 'Known Failures' in category:
                        rv += indent('No known JIRA tickets. You should fix that ಠ_ಠ\n',
                                     width=8)

                    if verbosity > 2 or category != 'Known Failures':
                        rv += indent(f.errorDetails.strip(), width=12) + '\n'
            else:
                rv += indent('No failures in this category.', width=8) + '\n'
        else:
            n = len(category_failures)
            rv += indent('{n} {f} in this category'.format(n=n,
                                                           f=numberize('failure', n)),
                         width=8)

    return rv
示例#6
0
 def pretty(self):
     text = f"prove <{self.claim}> via {self.kind}"
     if self.assumption:
         text = f'assuming <{self.assumption}>, ' + text
     if self.subproofs:
         text += ':\n'
         subtext = '\n'.join(subproof.pretty for subproof in self.subproofs)
         text += indent(subtext, '|   ')
     return text
示例#7
0
def format_noise_failures(failure_dict, verbosity):
    rv = ""

    for category, category_failures in failure_dict.items():
        rv += indent(str(category), width=4) + '\n'

        if verbosity > 1:
            if category_failures:
                for f in category_failures:
                    rv += indent(pasteable_name(f).strip(), width=8) + '\n'
                    if verbosity > 2 or category != 'Known Failures':
                        rv += indent(f.errorDetails.strip(), width=12) + '\n'
            else:
                rv += indent('No failures in this category.', width=8) + '\n'
        else:
            n = len(category_failures)
            rv += indent('{n} {f} in this category'.format(n=n,
                                                           f=numberize('failure', n)),
                         width=8)

    return rv
    if 'max_zoom' in props:
        max_zoom = ET.SubElement(entry, "max-zoom")
        max_zoom.text = str(props['max_zoom'])

    geometry = source.get('geometry')
    if geometry:

        def coord_str(coord):
            return str(round(coord, 6))

        bounds = ET.SubElement(entry, "bounds")
        lons = [p[0] for ring in geometry['coordinates'] for p in ring]
        lats = [p[1] for ring in geometry['coordinates'] for p in ring]
        bounds.set('min-lon', coord_str(min(lons)))
        bounds.set('min-lat', coord_str(min(lats)))
        bounds.set('max-lon', coord_str(max(lons)))
        bounds.set('max-lat', coord_str(max(lats)))

        for ring in geometry['coordinates']:
            shape = ET.SubElement(bounds, "shape")
            for p in ring:
                point = ET.SubElement(shape, "point")
                point.set('lon', coord_str(p[0]))
                point.set('lat', coord_str(p[1]))

util.indent(root)

tree = ET.ElementTree(root)
with io.open("imagery.xml", mode='wb') as f:
    tree.write(f)
示例#9
0
 def error_report(msg):
     print util.indent(msg)
     print util.indent("Selector was: %s" % pprint(dict(selector)))
     print util.indent("Update was %s" % pprint(dict(update)))
     print util.indent("Upsert from collection1: %s" % ret1)
     print util.indent("Upsert from collection2: %s" % ret2)
示例#10
0
            min_zoom = ET.SubElement(entry, "min-zoom")
            min_zoom.text = str(extent['min_zoom'])

        if 'max_zoom' in extent:
            max_zoom = ET.SubElement(entry, "max-zoom")
            max_zoom.text = str(extent['max_zoom'])

        if 'bbox' in extent or 'polygon' in extent:
            bounds = ET.SubElement(entry, "bounds")

            # Rounding to the nearest ~10cm
            if 'bbox' in extent:
                bounds.set('min-lat', str(round(extent['bbox']['min_lat'],6)))
                bounds.set('min-lon', str(round(extent['bbox']['min_lon'],6)))
                bounds.set('max-lat', str(round(extent['bbox']['max_lat'],6)))
                bounds.set('max-lon', str(round(extent['bbox']['max_lon'],6)))

            if 'polygon' in extent:
                for ring in extent['polygon']:
                    shape = ET.SubElement(bounds, "shape")
                    for p in ring:
                        point = ET.SubElement(shape, "point")
                        point.set('lon', str(round(p[0],6)))
                        point.set('lat', str(round(p[1],6)))

util.indent(root)

tree = ET.ElementTree(root)
with open("imagery.xml", 'wb') as f:
    tree.write(f)
示例#11
0
    def pretty(self, s):
        def error_paths(self):
            if type(self) is not CheckError:
                return [[self]]
            paths = []
            for _, e in self.errors:
                paths.extend([[self] + p for p in error_paths(e)])
            return paths

        paths = error_paths(self)

        def pretty(e):
            if type(e[-1]) is ConfusionError:
                return e[-1].pretty(s)
            return '{}\n{}'.format(U.highlight(e[-2].ast, s), str(e[-1]))

        if len(paths) == 1:
            return pretty(paths[0])

        value_errors = [
            p for p in paths if type(p[-1]) is ValueError
            and 'Unbound identifier' not in str(p[-1])
        ]
        unbound_idents = [
            p for p in paths
            if type(p[-1]) is ValueError and 'Unbound identifier' in str(p[-1])
        ]
        unif_errors = [p for p in paths if type(p[-1]) is T.UnificationError]
        grouped_unif_errors = {}
        for reason in {p[-1].reason for p in unif_errors}:
            grouped_unif_errors[reason] = [
                p for p in unif_errors if p[-1].reason == reason
            ]
        confusion_errors = [p for p in paths if type(p[-1]) is ConfusionError]

        summary = ''
        if len(value_errors) > 0:
            summary = '{} value errors'.format(len(value_errors))
        if len(unbound_idents) > 0:
            summary += '\n{} unbound identifier errors'.format(
                len(unbound_idents))
        if len(grouped_unif_errors.items()) > 0:
            for reason, subpaths in sorted(grouped_unif_errors.items(),
                                           key=lambda a: -len(a[1])):
                summary += '\n{} unification errors ({})'.format(
                    len(subpaths), reason)
        if len(confusion_errors) > 0:
            summary += '\n{} confusion errors'.format(len(confusion_errors))

        if len(value_errors) > 0:
            header = '' if summary == '' else 'Among\n' + U.indent(
                '  ', summary)
            return header + ''.join('\n' + pretty(e) for e in value_errors)
        if len(confusion_errors) > 0:
            header = '' if summary == '' else 'Among\n' + U.indent(
                '  ', summary)
            return header + ''.join('\n' + pretty(e) for e in confusion_errors)

        coords = {U.coords(p[-2].ast) for p in paths}
        footer = summary if len(paths) > 10 else ''.join(
            {'\n' + str(p[-1])
             for p in paths})
        return '{}{}'.format(
            '\n'.join(
                U.code_pointers(row, [c for r, c in coords if r == row], s)
                for row in {r
                            for r, _ in coords}), footer)
示例#12
0
 def __str__(self):
     return '{}\nfor:\n{}'.format(
         P.pretty(P.explode(self.ast)),
         '\n'.join('{}\n{}'.format(r.name, U.indent('  ', str(e)))
                   for r, e in self.errors))
示例#13
0
            folder_layer0.append(pop_pm)
            cli_code = x[1][0:8]
            prev_cli = cli_code
            equipment = x[5] + ','
            comment =  x[1] + ','


        site = cli_code
        street = x[2]
        country = x[4]
        city = ''
        state = ''
        long_lat = getLocation(cli_code)
        long= long_lat[1]
        lat = long_lat[0]

        if x[3] is not None :
            st_list = x[3].split()
            try:
                city = ' '.join(st_list[0:-2])
            except Exception as err:
                print(st_list)
                print('Handling run-time error:', err)
            state = st_list[-2]
        # ef __init__(self, cli_code,site,street,city,state,country,equipment,long,lat)


    indent(kml)
    tree = etree.ElementTree(kml)
    tree.write("out_put.kml", xml_declaration=True, encoding='utf-8', method="xml")
def error_report(msg, names1, names2):
    print util.alert("%s" % msg, "fail")
    print util.indent(util.alert("Collection1: %s" % names1, "fail"))
    print util.indent(util.alert("Collection2: %s" % names2, "fail"))