summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/tools/w3ctestlib/Suite.py
blob: c5fa03a155fa72d8bae59a0b5d549b053f502f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python
# CSS Test Suite Manipulation Library
# Initial code by fantasai, joint copyright 2010 W3C and Microsoft
# Licensed under BSD 3-Clause: <http://www.w3.org/Consortium/Legal/2008/03-bsd-license>

import OutputFormats
import Utils
from Groups import TestGroup, excludeDirs
from Sources import SourceTree, SourceCache
from shutil import copytree, rmtree
from os.path import join
import os
from mercurial import ui as UserInterface, hg

class TestSuite:
  """Representation of a standard CSS test suite."""

  def __init__(self, name, title, specUri, draftUri, sourceCache = None, ui = None):
    self.name = name
    self.title = title
    self.specroot = specUri
    self.draftroot = draftUri

    self.ui = ui if ui else UserInterface.ui()
    self.defaultReftestRelpath='reftest.list'
    self.groups = {}
    self.sourcecache = sourceCache if sourceCache else SourceCache(SourceTree(hg.repository(self.ui, '.')))
    self.formats = ('html4', 'xhtml1', 'xhtml1print') # XXX FIXME, hardcoded list is lame
    self.rawgroups = {}

  def addTestsByExt(self, dir, ext, groupName='', groupTitle=''):
    """Add tests from directory `dir` by file extension (via `ext`, e.g. ext='.xht').
    """
    group = TestGroup(self.sourcecache, dir, selfTestExt=ext,
                      name=groupName, title=groupTitle, ui = self.ui)
    self.addGroup(group)


  def addTestsByList(self, dir, filenames, groupName='', groupTitle=''):
    """Add tests from directory `dir`, via file name list `filenames`.
    """
    group = TestGroup(self.sourcecache, dir, selfTestList=filenames,
                      name=groupName, title=groupTitle, ui = self.ui)
    self.addGroup(group)

  def addReftests(self, dir, manifestPath, groupName='', groupTitle=''):
    """Add tests by importing context of directory `dir` and importing all
       tests listed in the `reftestManifestName` manifest inside `dir`.
    """
    group = TestGroup(self.sourcecache,
                      dir, manifestPath=manifestPath,
                      manifestDest=self.defaultReftestRelpath,
                      name=groupName, title=groupTitle, ui = self.ui)
    self.addGroup(group)

  def addGroup(self, group):
    """ Add CSSTestGroup `group` to store. """
    master = self.groups.get(group.name)
    if master:
      master.merge(group)
    else:
      self.groups[group.name] = group

  def addRaw(self, dir, relpath):
    """Add the contents of directory `dir` to the test suite by copying
       (not processing). Note this means such tests will not be indexed.
       `relpath` gives the directory's path within the build destination.
    """
    self.rawgroups[dir] = relpath

  def setFormats(self, formats):
    self.formats = formats
    
  def buildInto(self, dest, indexer):
    """Builds test suite through all OutputFormats into directory at path `dest`
       or through OutputFormat destination `dest`, using Indexer `indexer`.
    """
    if isinstance(dest, OutputFormats.BasicFormat):
      formats = (dest,)
      dest = dest.root
    else:
      formats = []
      for format in self.formats:
        if (format == 'html4'):
          formats.append(OutputFormats.HTMLFormat(dest, self.sourcecache.sourceTree))
        elif (format == 'html5'):
          formats.append(OutputFormats.HTML5Format(dest, self.sourcecache.sourceTree))
        elif (format == 'xhtml1'):
          formats.append(OutputFormats.XHTMLFormat(dest, self.sourcecache.sourceTree))
        elif (format == 'xhtml1print'):
          formats.append(OutputFormats.XHTMLPrintFormat(dest, self.sourcecache.sourceTree, self.title))
        elif (format == 'svg'):
          formats.append(OutputFormats.SVGFormat(dest, self.sourcecache.sourceTree))

    for format in formats:
      for group in self.groups.itervalues():
        group.build(format)

    for group in self.groups.itervalues():
      indexer.indexGroup(group)

    for format in formats:
      indexer.writeIndex(format)


    rawtests = []
    for src, relpath in self.rawgroups.items():
      copytree(src, join(dest,relpath))
      for (root, dirs, files) in os.walk(join(dest,relpath)):
        for xdir in excludeDirs:
          if xdir in dirs:
            dirs.remove(xdir)
            rmtree(join(root,xdir))
        rawtests.extend(
          [join(Utils.relpath(root,dest),file)
           for file in files]
        )

    rawtests.sort()
    indexer.writeOverview(dest, addTests=rawtests)