3
  	   ™ˆËÔ0¿×  #   ›ˆl–Ðz¾”Ëm
qA3q¶®21hßÕ„à|ÀØ ?÷     ›#!/usr/bin/python3
# GLib Testing Framework Utility			-*- Mode: python; -*-
# Copyright (C) 2007 Imendio AB
# Authors: Tim Janik
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <http://www.gnu.org/licenses/>.

# Deprecated: Since GLib 2.62, gtester and gtester-report have been deprecated
# in favour of TAP.

import datetime
import optparse
import sys, re, xml.dom.minidom

try:
    import subunit
    from subunit import iso8601
    from testtools.content import Content, ContentType
    mime_utf8 = ContentType('text', 'plain', {'charset': 'utf8'})
except ImportError:
    subunit = None


# xml utilities
def find_child (node, child_name):
  for child in node.childNodes:
    if child.nodeName == child_name:
      return child
  return None
def list_children (node, child_name):
  rlist = []
  for child in node.childNodes:
    if child.nodeName == child_name:
      rlist += [ child ]
  return rlist
def find_node (node, name = None):
  if not node or node.nodeName == name or not name:
    return node
  for child in node.childNodes:
    c = find_node (child, name)
    if c:
      return c
  return None
def node_as_text (node, name = None):
  if name:
    node = find_node (node, name)
  txt = ''
  if node:
    if node.nodeValue:
      txt += node.nodeValue
    for child in node.childNodes:
      txt += node_as_text (child)
  return txt
def attribute_as_text (node, aname, node_name = None):
  node = find_node (node, node_name)
  if not node:
    return ''
  attr = node.attributes.get (aname, '')
  if hasattr (attr, 'value'):
    return attr.value
  return ''

# HTML utilities
def html_indent_string (n):
  uncollapsible_space = ' &nbsp;' # HTML won't compress alternating sequences of ' ' and '&nbsp;'
  string = ''
  for i in range (0, int((n + 1) / 2)):
    string += uncollapsible_space
  return string

# TestBinary object, instantiated per test binary in the log file
class TestBinary:
  def __init__ (self, name):
    self.name = name
    self.testcases = []
    self.duration = 0
    self.success_cases = 0
    self.skipped_cases = 0
    self.file = '???'
    self.random_seed = ''

# base class to handle processing/traversion of XML nodes
class TreeProcess:
  def __init__ (self):
    self.nest_level = 0
  def trampoline (self, node):
    name = node.nodeName
    if name == '#text':
      self.handle_text (node)
    else:
      try:	method = getattr (self, 'handle_' + re.sub ('[^a-zA-Z0-9]', '_', name))
      except:	method = None
      if method:
        return method (node)
      else:
        return self.process_recursive (name, node)
  def process_recursive (self, node_name, node):
    self.process_children (node)
  def process_children (self, node):
    self.nest_level += 1
    for child in node.childNodes:
      self.trampoline (child)
    self.nest_level += 1

# test report reader, this class collects some statistics and merges duplicate test binary runs
class ReportReader (TreeProcess):
  def __init__ (self):
    TreeProcess.__init__ (self)
    self.binary_names = []
    self.binaries = {}
    self.last_binary = None
    self.info = {}
  def binary_list (self):
    lst = []
    for name in self.binary_names:
      lst += [ self.binaries[name] ]
    return lst
  def get_info (self):
    return self.info
  def handle_info (self, node):
    dn = find_child (node, 'package')
    self.info['package'] = node_as_text (dn)
    dn = find_child (node, 'version')
    self.info['version'] = node_as_