Author: hwright
Date: Mon Jul 26 16:46:29 2010
New Revision: 979357

URL: http://svn.apache.org/viewvc?rev=979357&view=rev
Log:
Initial import of Mouse into Apache Labs.

There is still much work to do, and currently has failing tests.

Added:
    labs/mouse/README
    labs/mouse/mouse.py   (with props)
    labs/mouse/resources/
    labs/mouse/resources/plain-rat.xsl
    labs/mouse/tests/   (with props)
    labs/mouse/tests/__init__.py
    labs/mouse/tests/data/
    labs/mouse/tests/data/expected_output/
    labs/mouse/tests/data/expected_output/greek_vanilla
    labs/mouse/tests/data/expected_output/greek_vanilla.xml
    labs/mouse/tests/data/greek/
    labs/mouse/tests/data/greek.tar.bz2   (with props)
    labs/mouse/tests/data/greek.tar.gz   (with props)
    labs/mouse/tests/data/greek.zip   (with props)
    labs/mouse/tests/data/greek/A/
    labs/mouse/tests/data/greek/A/B/
    labs/mouse/tests/data/greek/A/B/E/
    labs/mouse/tests/data/greek/A/B/E/alpha
    labs/mouse/tests/data/greek/A/B/E/beta
    labs/mouse/tests/data/greek/A/B/F/
    labs/mouse/tests/data/greek/A/B/lambda
    labs/mouse/tests/data/greek/A/C/
    labs/mouse/tests/data/greek/A/D/
    labs/mouse/tests/data/greek/A/D/G/
    labs/mouse/tests/data/greek/A/D/G/pi
    labs/mouse/tests/data/greek/A/D/G/rho
    labs/mouse/tests/data/greek/A/D/G/tau
    labs/mouse/tests/data/greek/A/D/H/
    labs/mouse/tests/data/greek/A/D/H/chi
    labs/mouse/tests/data/greek/A/D/H/omega
    labs/mouse/tests/data/greek/A/D/H/psi
    labs/mouse/tests/data/greek/A/D/gamma
    labs/mouse/tests/data/greek/A/mu
    labs/mouse/tests/data/greek/iota
    labs/mouse/tests/test_mouse.py   (with props)
Modified:
    labs/mouse/   (props changed)

Propchange: labs/mouse/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+*.pyc

Added: labs/mouse/README
URL: http://svn.apache.org/viewvc/labs/mouse/README?rev=979357&view=auto
==============================================================================
--- labs/mouse/README (added)
+++ labs/mouse/README Mon Jul 26 16:46:29 2010
@@ -0,0 +1,4 @@
+Mouse is a simple version of the Apache Release Audit Tool (RAT).  Written in
+Python, Mouse is intended to be easy to improve and expand, and to integrate
+well with existing tooling, such as post-commit hook scripts.  To learn more
+about how to use Mouse, run './mouse.py --help'.

Added: labs/mouse/mouse.py
URL: http://svn.apache.org/viewvc/labs/mouse/mouse.py?rev=979357&view=auto
==============================================================================
--- labs/mouse/mouse.py (added)
+++ labs/mouse/mouse.py Mon Jul 26 16:46:29 2010
@@ -0,0 +1,254 @@
+#!/usr/bin/env python
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+'''mouse is a lighter, friendlier version of RAT (the ASF Release Audit Tool).
+
+mouse is intended to replace RAT as a tool for checking license compliance
+within source code repositories, release archives, and directory trees.  It
+is intended to be modular, so as to be invoked from any number of places,
+including build scripts and post-commit hooks.
+
+mouse generates reports in the same format as RAT, and accepts the same
+arguments, excepting the fact that mouse does not modify files as part of
+its operation.  mouse will not attempt to insert missing license headers, but
+it will notify the user of their absence.
+
+For information about how to use mouse, run 'mouse.py --help'.'''
+
+
+import os
+import sys
+import tarfile
+import zipfile
+import optparse
+
+import xml.etree.cElementTree as ElementTree
+
+
+# Some constants
+VERSION = '0.1'
+
+resources_path = os.path.join(sys.path[0], 'resources')
+
+
+class _UnknownArchiveError(Exception):
+  '''An exception to communicate we've discovered a type of archive we can't
+  handle.'''
+
+  def __init__(self, target):
+    self.target = target
+
+  def __str__(self):
+    return "Unable to read archive '%s'" % self.target
+
+
+class Resource(object):
+
+  def __init__(self, name):
+    self._name = name
+
+  def to_element(self):
+    elem = ElementTree.Element('resource')
+    elem.set('name', self._name)
+
+    elem.append(ElementTree.Element('header-sample'))
+    elem.append(ElementTree.Element('header-type'))
+    elem.append(ElementTree.Element('license-family'))
+    elem.append(ElementTree.Element('license-approval'))
+    elem.append(ElementTree.Element('type'))
+
+    return elem
+
+
+def generate_report(items):
+  '''Run mouse on the given TARGET, using the OPTIONS to modify behavior.
+
+  In general usage, OPTIONS will be a result of using an optparse.OptionParser
+  object created as a result of parsing the command line.  Direct callers
+  of this function should mimic the behavior of such an object.
+
+  ITEMS is a generator (or other callable which will produce an iterable)
+  which returns objects which mouse is to process.  ITEMS should return tuples
+  of the form (LABEL, FILE), where LABEL is a textual label for the object, and
+  FILE is a file-like object which can be used to get the text of the 
object.'''
+
+  resources = []
+  for item in items():
+    resources.append(Resource(item[0]))
+
+  return resources
+
+
+def process_report(report):
+  '''Given REPORT, generate xml output representing its results.'''
+
+  root = ElementTree.Element('rat-report')
+
+  for resource in report:
+    root.append(resource.to_element())
+
+  return ElementTree.tostring(root)
+
+
+def transform_xslt(output_xml, stylesheet):
+  '''Transform OUTPUT_XML, which should be valid xml (usually the result of
+  calling process_report_xml()), according to the rules given in STYLESHEET.'''
+
+  print output_xml
+  return output_xml
+
+
+def filter_excludes(items, excludes):
+  '''Return a filtered version of ITEMS, according to EXCLUDES.
+  
+  EXCLUDES should be a list of regular expression objects.'''
+
+  def filter_generator():
+    for item in items():
+      matched = False
+      for exclude in excludes:
+        if exclude.match(item[0]):
+          matched = True
+          break
+      if matched:
+        continue
+      else:
+        yield item
+
+  return filter_generator
+
+
+def get_items(target):
+  '''Using TARGET as the source, return a generator or iterable suitable for
+  use as input to generate_report().'''
+
+  # is the thing a directory?
+  if os.path.isdir(target):
+    def dir_gen_func():
+      for (dirpath, dirnames, filenames) in os.walk(target):
+        # ignore .svn directories, if in a working copy
+        if '.svn' in dirnames:
+          dirnames.remove('.svn')
+
+        for filename in filenames:
+          name = os.path.join(dirpath, filename)
+          yield (name, open(name))
+
+    return dir_gen_func
+  
+  # is the thing a tarfile?
+  if tarfile.is_tarfile(target):
+    tar = tarfile.open(target, 'r')
+
+    def tar_gen_func():
+      for info in tar.getmembers():
+        if info.isdir():
+          continue
+        yield (info.name, tar.extractfile(info))
+
+    return tar_gen_func
+
+  # is the thing a zipfile?
+  if zipfile.is_zipfile(target):
+    zip = zipfile.ZipFile(target, 'r')
+
+    def zip_gen_func():
+      for info in zip.infolist():
+        if info.filename[-1] == '/':
+          continue
+        yield (info.filename, zip.open(info))
+
+    return zip_gen_func
+
+  # if we get to this point, we've no idea what the user gave us, so throw
+  # an appropriate exception
+  raise _UnknownArchiveError(target)
+
+
+def match(items):
+  def match_generator():
+    for item in items():
+      yield (item[0],)
+
+  return match_generator
+
+
+def main():
+  'Parse the command line arguments, and use them to generate a mouse report.'
+
+  # set up the option parser
+  usage = 'usage: %prog [options] <DIR|TARBALL>'
+  version = '%prog ' + VERSION
+  parser = optparse.OptionParser(usage=usage, version=version)
+  parser.add_option('-d', '--dir', action='store_true',
+                    help='Used to indicate source when using --exclude')
+  parser.add_option('-e', '--exclude', action='store', metavar='expression',
+                    help='Excludes files matching <expression>. Note that ' +
+                         '--dir is required when using this parameter. ' +
+                         'Allows multiple arguments.')
+  parser.add_option('-s', '--stylesheet', action='store', metavar='arg',
+                    help='XSLT stylesheet to use when creating the report.  ' +
+                         'Not compatible with -x')
+  parser.add_option('-x', '--xml', action='store_true',
+                    help='Output the report in raw XML format.  Not '
+                         'compatible with -s')
+
+  (options, args) = parser.parse_args()
+
+  # detect required argument bogosity
+  if options.exclude and not options.dir:
+    parser.error('--dir required when using --exclude')
+  if options.stylesheet and options.xml:
+    parser.error('--stylesheet and --xml are mutually exclusive')
+  if options.stylesheet:
+    try:
+      import libxslt
+    except:
+      parser.error('cannot find python xslt module, needed for --stylesheet')
+  if len(args) < 1:
+    parser.error('no tarball or directory given')
+  if len(args) > 1:
+    parser.error('mouse only supports one tarball or directory per run')
+
+  try:
+    items = get_items(args[0])
+  except IOError:
+    parser.error('error reading \'%s\'' % args[0])
+  except _UnknownArchiveError as ex:
+    parser.error(str(ex))
+
+  if options.exclude:
+    items = filter_excludes(get_items(args[0]),
+                            open(options.exclude).read().split())
+
+  report_items = match(items)
+  report = generate_report(report_items)
+
+  output = process_report(report)
+  if options.stylesheet:
+    output = transform_xslt(report, options.stylesheet)
+  elif not options.xml:
+    output = transform_xslt(report, os.path.join(resources_path,
+                                                 'plain-rat.xsl'))
+
+  print output
+
+
+if __name__ == '__main__':
+  main()

Propchange: labs/mouse/mouse.py
------------------------------------------------------------------------------
    svn:executable = *

Added: labs/mouse/resources/plain-rat.xsl
URL: 
http://svn.apache.org/viewvc/labs/mouse/resources/plain-rat.xsl?rev=979357&view=auto
==============================================================================
--- labs/mouse/resources/plain-rat.xsl (added)
+++ labs/mouse/resources/plain-rat.xsl Mon Jul 26 16:46:29 2010
@@ -0,0 +1,90 @@
+<?xml version='1.0' ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one   *
+ or more contributor license agreements.  See the NOTICE file *
+ distributed with this work for additional information        *
+ regarding copyright ownership.  The ASF licenses this file   *
+ to you under the Apache License, Version 2.0 (the            *
+ "License"); you may not use this file except in compliance   *
+ with the License.  You may obtain a copy of the License at   *
+                                                              *
+   http://www.apache.org/licenses/LICENSE-2.0                 *
+                                                              *
+ Unless required by applicable law or agreed to in writing,   *
+ software distributed under the License is distributed on an  *
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ KIND, either express or implied.  See the License for the    *
+ specific language governing permissions and limitations      *
+ under the License.                                           *
+-->
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
+<xsl:output method='text'/>
+<xsl:template match='/'>
+*****************************************************
+Summary
+-------
+Notes: <xsl:value-of 
select='count(descendant::type[attribute::name="notice"])'/>
+Binaries: <xsl:value-of 
select='count(descendant::type[attribute::name="binary"])'/>
+Archives: <xsl:value-of 
select='count(descendant::type[attribute::name="archive"])'/>
+Standards: <xsl:value-of 
select='count(descendant::type[attribute::name="standard"])'/>
+
+Apache Licensed: <xsl:value-of 
select='count(descendant::header-type[attribute::name="AL   "])'/>
+Generated Documents: <xsl:value-of 
select='count(descendant::header-type[attribute::name="GEN  "])'/>
+
+JavaDocs are generated and so license header is optional
+Generated files do not required license headers
+
+<xsl:value-of 
select='count(descendant::header-type[attribute::name="?????"])'/> Unknown 
Licenses
+
+*******************************
+
+Unapproved licenses:
+
+<xsl:for-each select='descendant::resource[license-approval/@name="false"]'>
+  <xsl:text>  </xsl:text>
+  <xsl:value-of select='@name'/>
+  <xsl:text>
+</xsl:text>
+</xsl:for-each>
+*******************************
+
+Archives:
+<xsl:for-each select='descendant::resource[type/@name="archive"]'>
+ + <xsl:value-of select='@name'/>
+ <xsl:text>
+ </xsl:text>
+ </xsl:for-each>
+*****************************************************
+  Files with Apache License headers will be marked AL
+  Binary files (which do not require AL headers) will be marked B
+  Compressed archives will be marked A
+  Notices, licenses etc will be marked N
+ <xsl:for-each select='descendant::resource'>
+  <xsl:choose>
+        <xsl:when test='license-approval/@name="false"'>!</xsl:when>
+        <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
+ </xsl:choose>
+ <xsl:choose>
+        <xsl:when test='type/@name="notice"'>N    </xsl:when>
+        <xsl:when test='type/@name="archive"'>A    </xsl:when>
+        <xsl:when test='type/@name="binary"'>B    </xsl:when>
+        <xsl:when test='type/@name="standard"'><xsl:value-of 
select='header-type/@name'/></xsl:when>
+        <xsl:otherwise>!!!!!</xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select='@name'/>
+ <xsl:text>
+ </xsl:text>
+ </xsl:for-each>
+ *****************************************************
+ Printing headers for files without AL header...
+ 
+ <xsl:for-each select='descendant::resource[header-type/@name="?????"]'>
+ =======================================================================
+ ==<xsl:value-of select='@name'/>
+ =======================================================================
+<xsl:value-of select='header-sample'/>
+</xsl:for-each>
+</xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

Propchange: labs/mouse/tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+*.pyc

Added: labs/mouse/tests/__init__.py
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/__init__.py?rev=979357&view=auto
==============================================================================
    (empty)

Added: labs/mouse/tests/data/expected_output/greek_vanilla
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/expected_output/greek_vanilla?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/expected_output/greek_vanilla (added)
+++ labs/mouse/tests/data/expected_output/greek_vanilla Mon Jul 26 16:46:29 2010
@@ -0,0 +1,118 @@
+*****************************************************
+Summary
+-------
+Notes: 0
+Binaries: 0
+Archives: 0
+Standards: 12
+
+Apache Licensed: 0
+Generated Documents: 0
+
+JavaDocs are generated and so license header is optional
+Generated files do not required license headers
+
+12 Unknown Licenses
+
+*******************************
+
+Unapproved licenses:
+
+  data/greek/iota
+  data/greek/A/mu
+  data/greek/A/B/lambda
+  data/greek/A/B/E/alpha
+  data/greek/A/B/E/beta
+  data/greek/A/D/gamma
+  data/greek/A/D/G/pi
+  data/greek/A/D/G/rho
+  data/greek/A/D/G/tau
+  data/greek/A/D/H/chi
+  data/greek/A/D/H/omega
+  data/greek/A/D/H/psi
+
+*******************************
+
+Archives:
+
+*****************************************************
+  Files with Apache License headers will be marked AL
+  Binary files (which do not require AL headers) will be marked B
+  Compressed archives will be marked A
+  Notices, licenses etc will be marked N
+ !????? data/greek/iota
+ !????? data/greek/A/mu
+ !????? data/greek/A/B/lambda
+ !????? data/greek/A/B/E/alpha
+ !????? data/greek/A/B/E/beta
+ !????? data/greek/A/D/gamma
+ !????? data/greek/A/D/G/pi
+ !????? data/greek/A/D/G/rho
+ !????? data/greek/A/D/G/tau
+ !????? data/greek/A/D/H/chi
+ !????? data/greek/A/D/H/omega
+ !????? data/greek/A/D/H/psi
+ 
+ *****************************************************
+ Printing headers for files without AL header...
+ 
+ 
+ =======================================================================
+ ==data/greek/iota
+ =======================================================================
+This is the file 'iota'.
+
+ =======================================================================
+ ==data/greek/A/mu
+ =======================================================================
+This is the file 'mu'.
+
+ =======================================================================
+ ==data/greek/A/B/lambda
+ =======================================================================
+This is the file 'lambda'.
+
+ =======================================================================
+ ==data/greek/A/B/E/alpha
+ =======================================================================
+This is the file 'alpha'.
+
+ =======================================================================
+ ==data/greek/A/B/E/beta
+ =======================================================================
+This is the file 'beta'.
+
+ =======================================================================
+ ==data/greek/A/D/gamma
+ =======================================================================
+This is the file 'gamma'.
+
+ =======================================================================
+ ==data/greek/A/D/G/pi
+ =======================================================================
+This is the file 'pi'.
+
+ =======================================================================
+ ==data/greek/A/D/G/rho
+ =======================================================================
+This is the file 'rho'.
+
+ =======================================================================
+ ==data/greek/A/D/G/tau
+ =======================================================================
+This is the file 'tau'.
+
+ =======================================================================
+ ==data/greek/A/D/H/chi
+ =======================================================================
+This is the file 'chi'.
+
+ =======================================================================
+ ==data/greek/A/D/H/omega
+ =======================================================================
+This is the file 'omega'.
+
+ =======================================================================
+ ==data/greek/A/D/H/psi
+ =======================================================================
+This is the file 'psi'.

Added: labs/mouse/tests/data/expected_output/greek_vanilla.xml
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/expected_output/greek_vanilla.xml?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/expected_output/greek_vanilla.xml (added)
+++ labs/mouse/tests/data/expected_output/greek_vanilla.xml Mon Jul 26 16:46:29 
2010
@@ -0,0 +1,13 @@
+<rat-report><resource name='data/greek/iota'><header-sample>This is the file 
'iota'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/mu'><header-sample>This is the file 'mu'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/B/lambda'><header-sample>This is the file 'lambda'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/B/E/alpha'><header-sample>This is the file 'alpha'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/B/E/beta'><header-sample>This is the file 'beta'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/gamma'><header-sample>This is the file 'gamma'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/G/pi'><header-sample>This is the file 'pi'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/G/rho'><header-sample>This is the file 'rho'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/G/tau'><header-sample>This is the file 'tau'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/H/chi'><header-sample>This is the file 'chi'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/H/omega'><header-sample>This is the file 'omega'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource><resource 
name='data/greek/A/D/H/psi'><header-sample>This is the file 'psi'.
+</header-sample><header-type name='?????'/><license-family 
name='?????'/><license-approval name='false'/><type 
name='standard'/></resource></rat-report>

Added: labs/mouse/tests/data/greek.tar.bz2
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek.tar.bz2?rev=979357&view=auto
==============================================================================
Binary file - no diff available.

Propchange: labs/mouse/tests/data/greek.tar.bz2
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: labs/mouse/tests/data/greek.tar.gz
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek.tar.gz?rev=979357&view=auto
==============================================================================
Binary file - no diff available.

Propchange: labs/mouse/tests/data/greek.tar.gz
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: labs/mouse/tests/data/greek.zip
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek.zip?rev=979357&view=auto
==============================================================================
Binary file - no diff available.

Propchange: labs/mouse/tests/data/greek.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: labs/mouse/tests/data/greek/A/B/E/alpha
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/B/E/alpha?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/B/E/alpha (added)
+++ labs/mouse/tests/data/greek/A/B/E/alpha Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'alpha'.

Added: labs/mouse/tests/data/greek/A/B/E/beta
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/B/E/beta?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/B/E/beta (added)
+++ labs/mouse/tests/data/greek/A/B/E/beta Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'beta'.

Added: labs/mouse/tests/data/greek/A/B/lambda
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/B/lambda?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/B/lambda (added)
+++ labs/mouse/tests/data/greek/A/B/lambda Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'lambda'.

Added: labs/mouse/tests/data/greek/A/D/G/pi
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/G/pi?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/G/pi (added)
+++ labs/mouse/tests/data/greek/A/D/G/pi Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'pi'.

Added: labs/mouse/tests/data/greek/A/D/G/rho
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/G/rho?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/G/rho (added)
+++ labs/mouse/tests/data/greek/A/D/G/rho Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'rho'.

Added: labs/mouse/tests/data/greek/A/D/G/tau
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/G/tau?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/G/tau (added)
+++ labs/mouse/tests/data/greek/A/D/G/tau Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'tau'.

Added: labs/mouse/tests/data/greek/A/D/H/chi
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/H/chi?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/H/chi (added)
+++ labs/mouse/tests/data/greek/A/D/H/chi Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'chi'.

Added: labs/mouse/tests/data/greek/A/D/H/omega
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/H/omega?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/H/omega (added)
+++ labs/mouse/tests/data/greek/A/D/H/omega Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'omega'.

Added: labs/mouse/tests/data/greek/A/D/H/psi
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/H/psi?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/H/psi (added)
+++ labs/mouse/tests/data/greek/A/D/H/psi Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'psi'.

Added: labs/mouse/tests/data/greek/A/D/gamma
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/D/gamma?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/D/gamma (added)
+++ labs/mouse/tests/data/greek/A/D/gamma Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'gamma'.

Added: labs/mouse/tests/data/greek/A/mu
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/A/mu?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/A/mu (added)
+++ labs/mouse/tests/data/greek/A/mu Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'mu'.

Added: labs/mouse/tests/data/greek/iota
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/data/greek/iota?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/data/greek/iota (added)
+++ labs/mouse/tests/data/greek/iota Mon Jul 26 16:46:29 2010
@@ -0,0 +1 @@
+This is the file 'iota'.

Added: labs/mouse/tests/test_mouse.py
URL: 
http://svn.apache.org/viewvc/labs/mouse/tests/test_mouse.py?rev=979357&view=auto
==============================================================================
--- labs/mouse/tests/test_mouse.py (added)
+++ labs/mouse/tests/test_mouse.py Mon Jul 26 16:46:29 2010
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+#
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#
+
+
+import os
+import re
+import sys
+import optparse
+import unittest
+
+import xml.etree.cElementTree as ElementTree
+
+# so that we can import mouse
+sys.path.append(os.path.dirname(sys.path[0]))
+
+import mouse
+
+data_path = os.path.join(sys.path[0], 'data')
+resources_path = os.path.join(os.path.dirname(sys.path[0]), 'resources')
+
+
+def _count_items(items):
+  'Return the number of items generated by ITEMS'
+  i = 0
+  for item in items():
+    i = i + 1
+  return i
+
+
+class TestReport(unittest.TestCase):
+  'Test generating reports'
+
+  def test_greek_vanilla_xml(self):
+    items = mouse.get_items(os.path.join(data_path, 'greek'))
+    report = mouse.generate_report(items)
+    output = mouse.process_report(report)
+    output_element = ElementTree.XML(output)
+    target_xml = open(os.path.join(data_path, 'expected_output',
+                                   'greek_vanilla.xml')).read()
+    target_element = ElementTree.XML(target_xml)
+    self.assertEqual(output_element, target_element)
+    
+  def test_greek_vanilla(self):
+    items = mouse.get_items(os.path.join(data_path, 'greek'))
+    report = mouse.generate_report(items)
+    output = mouse.process_report(report)
+    output = mouse.transform_xslt(output, os.path.join(resources_path,
+                                                       'plain-rat.xsl'))
+    self.assertEqual(output, open(os.path.join(data_path, 'expected_output',
+                                               'greek_vanilla')).read())
+
+
+class TestFilters(unittest.TestCase):
+  'Test filtering various files and patterns'
+
+  def test_single_exclude(self):
+    items = mouse.get_items(os.path.join(data_path, 'greek'))
+    self.assertEqual(12, _count_items(items))
+    items = mouse.filter_excludes(items, (re.compile('.*greek\/iota$'), ))
+    self.assertEqual(11, _count_items(items))
+
+
+class TestSources(unittest.TestCase):
+  'Test the parsing of various data sources.'
+
+  zip_path = os.path.join(data_path, 'greek.zip')
+  tar_gz_path = os.path.join(data_path, 'greek.tar.gz')
+  tar_bz2_path = os.path.join(data_path, 'greek.tar.bz2')
+  greek_path = os.path.join(data_path, 'greek')
+  iota_path = os.path.join(greek_path, 'iota')
+  latin_path = os.path.join(data_path, 'latin')
+
+  def _assert_items(self, path):
+    items = mouse.get_items(path)
+    self.assertEqual(12, _count_items(items))
+
+  def test_dir(self):
+    self._assert_items(self.greek_path)
+
+  def test_tar_gz(self):
+    self._assert_items(self.tar_gz_path)
+
+  def test_tar_bz2(self):
+    self._assert_items(self.tar_bz2_path)
+
+  def test_zip(self):
+    self._assert_items(self.zip_path)
+
+  def test_archive_error(self):
+    self.assertRaises(IOError, mouse.get_items, self.latin_path)
+
+  def test_bogus_filetype(self):
+    self.assertRaises(mouse._UnknownArchiveError, mouse.get_items,
+                      self.iota_path)
+
+
+if __name__ == '__main__':
+  # change the cwd to the directory
+  os.chdir(os.path.dirname(sys.argv[0]))
+
+  unittest.main()

Propchange: labs/mouse/tests/test_mouse.py
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to