automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/6] python tests: add "unit tests" on py-compile


From: Stefano Lattarini
Subject: [PATCH 3/6] python tests: add "unit tests" on py-compile
Date: Thu, 9 Jun 2011 16:15:24 +0200

* tests/py-compile-basic.test: New test.
* tests/py-compile-basic2.test: New test.
* tests/py-compile-basedir.test: Likewise.
* tests/py-compile-destdir.test: Likewise.
* tests/py-compile-env.test: Likewise.
* tests/py-compile-usage.test: Likewise.
* tests/Makefile.am (TESTS): Update.

Tested with python 2.0.1, 2.4.6, 2.6.6, 2.7.1, and 3.1.3.
---
 ChangeLog                     |   12 +++++++
 tests/Makefile.am             |    6 +++
 tests/Makefile.in             |    6 +++
 tests/py-compile-basedir.test |   51 +++++++++++++++++++++++++++++
 tests/py-compile-basic.test   |   64 +++++++++++++++++++++++++++++++++++++
 tests/py-compile-basic2.test  |   71 +++++++++++++++++++++++++++++++++++++++++
 tests/py-compile-destdir.test |   44 +++++++++++++++++++++++++
 tests/py-compile-env.test     |   60 ++++++++++++++++++++++++++++++++++
 tests/py-compile-usage.test   |   66 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 380 insertions(+), 0 deletions(-)
 create mode 100755 tests/py-compile-basedir.test
 create mode 100755 tests/py-compile-basic.test
 create mode 100755 tests/py-compile-basic2.test
 create mode 100755 tests/py-compile-destdir.test
 create mode 100755 tests/py-compile-env.test
 create mode 100755 tests/py-compile-usage.test

diff --git a/ChangeLog b/ChangeLog
index 6f2d7b1..f6e80ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2011-06-08  Stefano Lattarini  <address@hidden>
 
+       python tests: add "unit tests" on py-compile
+       * tests/py-compile-basic.test: New test.
+       * tests/py-compile-basic2.test: New test.
+       * tests/py-compile-basedir.test: Likewise.
+       * tests/py-compile-destdir.test: Likewise.
+       * tests/py-compile-env.test: Likewise.
+       * tests/py-compile-usage.test: Likewise.
+       * tests/Makefile.am (TESTS): Update.
+       Tested with python 2.0.1, 2.4.6, 2.6.6, 2.7.1, and 3.1.3.
+
+2011-06-08  Stefano Lattarini  <address@hidden>
+
        py-compile: the '--destdir' option now accepts a blank argument
        * lib/py-compile (Option parsing): Do not count an empty argument
        to `--destdir' or `--basedir' as a missing argument.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 33ae8bc..829e960 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -633,6 +633,12 @@ primary.test \
 primary2.test \
 primary3.test \
 proginst.test \
+py-compile-basic.test \
+py-compile-basic2.test \
+py-compile-basedir.test \
+py-compile-destdir.test \
+py-compile-env.test \
+py-compile-usage.test \
 python.test \
 python2.test \
 python3.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index d7a1761..47a334e 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -904,6 +904,12 @@ primary.test \
 primary2.test \
 primary3.test \
 proginst.test \
+py-compile-basic.test \
+py-compile-basic2.test \
+py-compile-basedir.test \
+py-compile-destdir.test \
+py-compile-env.test \
+py-compile-usage.test \
 python.test \
 python2.test \
 python3.test \
diff --git a/tests/py-compile-basedir.test b/tests/py-compile-basedir.test
new file mode 100755
index 0000000..d84c790
--- /dev/null
+++ b/tests/py-compile-basedir.test
@@ -0,0 +1,51 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the `--basedir' option of the `py-compile' script,
+
+required=python
+. ./defs || Exit 1
+
+set -e
+
+# We'll need to create files in `..', so that we need another level of
+# subdirectory in order not to clutter up the top-level tests directory.
+mkdir sandbox
+cd sandbox
+
+cp "$testsrcdir/../lib/py-compile" .
+
+f=__init__
+for d in foo foo/bar "`pwd`/foo" . .. ../foo ''; do
+  if test -z "$d"; then
+    d2=.
+  else
+    d2=$d
+  fi
+  ../install-sh -d "$d2" "$d2/sub" || Exit 99
+  : > "$d2/$f.py"
+  : > "$d2/sub/$f.py"
+  ./py-compile --basedir "$d" "$f.py" "sub/$f.py"
+  ls -l "$d2" "$d2/sub" # For debugging.
+  test -f "$d2/$f.pyc"
+  test -f "$d2/$f.pyo"
+  test -f "$d2/sub/$f.pyc"
+  test -f "$d2/sub/$f.pyo"
+  rm -f "$d2/$f.pyc" "$d2/$f.pyo" "$d2/sub/$f.pyc" "$d2/sub/$f.pyo"
+  find . | grep '\.py[co]$' && Exit 1
+done
+
+:
diff --git a/tests/py-compile-basic.test b/tests/py-compile-basic.test
new file mode 100755
index 0000000..5d8968c
--- /dev/null
+++ b/tests/py-compile-basic.test
@@ -0,0 +1,64 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test more basic functionalities of the `py-compile' script,
+# with "believable" python sources.  See also related test
+# `py-compile-basic2.test'.
+
+required=python
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir/../lib/py-compile" .
+
+cat > foo.py <<'END'
+# Try out some non-trivial sytanx in here.
+
+'''Module docstring'''
+
+def foo (*args, **kwargs):
+  """Function docstring
+  with embedded newline"""
+  return 1
+
+class Foo:
+  r"""Class docstring"""
+  def __init__(self):
+    r'''Method docstring
+        with
+        embedded
+        newlines'''
+    pass
+
+bar = baz = (1, (2,), [3, 4]); zardoz = 0;
+END
+
+cat > bar.py <<'END'
+# Import of non-existent modules, or assertion of flase conditions,
+# shouldn't cause problems, as it should be enough for the code to
+# be syntactically correct.
+import Automake.No.Such.Module
+assert False
+END
+
+./py-compile foo.py bar.py
+test -f foo.pyc
+test -f foo.pyo
+test -f bar.pyc
+test -f bar.pyo
+
+:
diff --git a/tests/py-compile-basic2.test b/tests/py-compile-basic2.test
new file mode 100755
index 0000000..0da0d42
--- /dev/null
+++ b/tests/py-compile-basic2.test
@@ -0,0 +1,71 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test more basic functionalities of the `py-compile' script, with
+# dummy python sources, but more complex directory layouts.  See also
+# related test `py-compile-basic.test'.
+
+required=python
+. ./defs || Exit 1
+
+set -e
+
+ocwd=`pwd` || Exit 99
+
+pyfiles="
+  foo.py
+  ./foo1.py
+  ../foo2.py
+  ../dir/foo3.py
+  $ocwd/foo4.py
+  sub/bar.py
+  sub/subsub/barbar.py
+  __init__.py
+  sub/__init__.py
+  1.py
+  .././_.py
+"
+
+lst='
+  dir/foo
+  dir/foo1
+  foo2
+  dir/foo3
+  foo4
+  dir/sub/bar
+  dir/sub/subsub/barbar
+  dir/__init__
+  dir/sub/__init__
+  dir/1
+  _
+'
+
+mkdir dir
+cd dir
+cp "$testsrcdir/../lib/py-compile" .
+mkdir sub sub/subsub
+touch $pyfiles
+./py-compile $pyfiles
+cd "$ocwd"
+
+for x in $lst; do echo $x.pyc; echo $x.pyo; done | sort > exp
+find . -name '*.py[co]' | sed 's|^\./||' | sort > got
+
+cat exp
+cat got
+diff exp got
+
+:
diff --git a/tests/py-compile-destdir.test b/tests/py-compile-destdir.test
new file mode 100755
index 0000000..3d122e6
--- /dev/null
+++ b/tests/py-compile-destdir.test
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the `--destdir' option of the `py-compile' script,
+
+required=python
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir/../lib/py-compile" .
+
+# Should not give false positives when grepping for it, so use
+# an "uncommon" string (with ugly CamelCase).
+destdir=TheDestDir
+
+mkdir sub $destdir $destdir/sub
+echo 'def foo (): return "foo"' > $destdir/foo.py
+echo 'def bar (): return "bar"' > $destdir/sub/bar.py
+
+./py-compile --destdir $destdir foo.py sub/bar.py
+ls -l $destdir $destdir/sub # For debugging.
+ls . sub | grep '\.py[co]$' && Exit 1
+test -f $destdir/foo.pyc
+test -f $destdir/foo.pyo
+test -f $destdir/sub/bar.pyc
+test -f $destdir/sub/bar.pyo
+strings $destdir/*.py[co] $destdir/sub/*.py[co] || : # For debugging.
+$FGREP $destdir $destdir/*.py[co] $destdir/sub/*.py[co] && Exit 1
+
+:
diff --git a/tests/py-compile-env.test b/tests/py-compile-env.test
new file mode 100755
index 0000000..a72d173
--- /dev/null
+++ b/tests/py-compile-env.test
@@ -0,0 +1,60 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Make sure `py-compile' honours the PYTHON environment variable.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir/../lib/py-compile" .
+
+cat > my-py <<'END'
+#!/bin/sh
+: > my-py.run
+END
+chmod a+x my-py
+
+mkdir sub1
+cd sub1
+
+PYTHON=: ../py-compile foo.py
+ls | grep . && Exit 1
+
+PYTHON=false ../py-compile foo.py && Exit 1
+ls | grep . && Exit 1
+
+PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py
+PYTHON='echo GrEpMe AndMeToo' ../py-compile foo.py | grep 'GrEpMe AndMeToo'
+ls | grep . && Exit 1
+
+cd ..
+mkdir sub2
+cd sub2
+
+PYTHON=../my-py ../py-compile foo.py
+test -f my-py.run
+ls | grep -v '^my-py\.run$' | grep . && Exit 1
+
+cd ..
+mkdir sub3
+cd sub3
+PATH=..$PATH_SEPARATOR$PATH; export PATH
+PYTHON=my-py py-compile foo.py
+test -f my-py.run
+ls | grep -v '^my-py\.run$' | grep . && Exit 1
+
+:
diff --git a/tests/py-compile-usage.test b/tests/py-compile-usage.test
new file mode 100755
index 0000000..c2a927f
--- /dev/null
+++ b/tests/py-compile-usage.test
@@ -0,0 +1,66 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test `py-compile --help', `py-compile --version', and that `py-compile'
+# correctly complains on wrong usage.
+
+. ./defs || Exit 1
+
+set -e
+
+cp "$testsrcdir/../lib/py-compile" .
+
+# --help
+
+./py-compile --help >stdout 2>stderr \
+  || { cat stdout; cat stderr >&2; Exit 1; }
+cat stdout
+test -s stderr && { cat stderr >&2; Exit 1; }
+grep '^Usage: py-compile .' stdout
+$FGREP ' [--basedir DIR]' stdout
+$FGREP ' [--destdir DIR]' stdout
+
+# --version
+
+./py-compile --version >stdout 2>stderr \
+  || { cat stdout; cat stderr >&2; Exit 1; }
+cat stdout
+test -s stderr && { cat stderr >&2; Exit 1; }
+year='20[0-9][0-9]' # Hopefully automake will be obsolete in 80 years ;-)
+month='(0[0-9]|1[012])'
+day='([012][0-9]|3[01])'
+hour='([01][0-9]|2[0123])'
+LC_ALL=C $EGREP "^py-compile $year-$month-$day\.$hour" stdout
+test `wc -l <stdout` -eq 1
+
+# Missing option argument.
+
+for opt in --basedir --destdir; do
+  ./py-compile $opt 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep "py-compile:.* [Mm]issing argument.*$opt" stderr
+done
+
+# Missing files.
+
+for args in '' '--basedir dir' '--destdir dir'; do
+  ./py-compile $args 2>stderr && { cat stderr >&2; Exit 1; }
+  cat stderr >&2
+  grep 'py-compile:.* [nN]o files given' stderr
+  grep "Try [\`'].*py-compile --help' for more information" stderr
+done
+
+:
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]