From b164c67fb2ae231d26cd6d3a28e5e524646171bd Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 12 Jan 2007 22:43:47 +0000 Subject: [PATCH] Merged from trunk 5549:5565 continue is only for loops (genone) Make FEATURES=test imply USE=test (genone) Add note that any value enables EPAUSE_IGNORE (genone) Use isinstance(foo, basestring) so that it can work with unicode strings too. Use dict.get() to prevent a potential (bug unlikely) KeyError. add support for user-customizable compression #9870 (SpankMan) docs for grabdict (WarnerBro) Commit unit tests, hey look THEY ARE BROKEN (WarnerBro) get_operator tests (WarnerBro) add some invalid operators to the test to denote that get_operator doesn't validate them, also make sure some common mis-typed things are tested (=> instead of >= fex) (WarnerBro) take some advice and use AssertEqual/NotEqual (WarnerBro) I owed brian harring 3.50, for th previous advice about assertEqual/NotEqual, oh, add dep_getcpv tests too (WarnerBro) getslot tests (WarnerBro) elaborate a bit on isjustname() (WarnerBro) isjustname tests (WarnerBro) For bug #50738, inform the user about the location of the timestamp file and that it can be removed to force sync. svn path=/main/branches/prefix/; revision=5617 --- bin/dodoc | 7 ++-- bin/doinfo | 20 ++++----- bin/ecompress | 44 ++++++++++++++++++++ bin/ecompressdir | 44 ++++++++++++++++++++ bin/emerge | 4 ++ bin/misc-functions.sh | 4 +- bin/prepalldocs | 44 ++++++++------------ bin/prepallinfo | 3 +- bin/prepallman | 17 ++++---- bin/prepinfo | 50 ++++++++--------------- bin/prepman | 49 +++++++--------------- man/make.conf.5 | 1 + pym/portage.py | 5 +++ pym/portage_dep.py | 2 +- pym/portage_exception.py | 2 +- pym/portage_util.py | 24 ++++++++++- tests/portage_dep/test_dep_getcpv.py | 25 ++++++++++++ tests/portage_dep/test_dep_getslot.py | 27 ++++++++++++ tests/portage_dep/test_get_operator.py | 26 ++++++++++++ tests/portage_dep/test_isjustname.py | 25 ++++++++++++ tests/portage_dep/test_isvalidatom.py | 36 ++++++++++++++++ tests/portage_dep/test_match_from_list.py | 6 +-- tests/portage_util/test_grabdict.py | 12 ++++++ tests/portage_util/test_normalizedPath.py | 3 +- tests/portage_util/test_stackDictList.py | 5 +-- tests/portage_util/test_stackDicts.py | 6 +-- tests/portage_util/test_stackLists.py | 4 +- 27 files changed, 349 insertions(+), 146 deletions(-) create mode 100755 bin/ecompress create mode 100755 bin/ecompressdir create mode 100644 tests/portage_dep/test_dep_getcpv.py create mode 100644 tests/portage_dep/test_dep_getslot.py create mode 100644 tests/portage_dep/test_get_operator.py create mode 100644 tests/portage_dep/test_isjustname.py create mode 100644 tests/portage_dep/test_isvalidatom.py create mode 100644 tests/portage_util/test_grabdict.py diff --git a/bin/dodoc b/bin/dodoc index adbf612df..b26a7659d 100755 --- a/bin/dodoc +++ b/bin/dodoc @@ -1,9 +1,10 @@ #!@BASH@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +# $Id$ if [ $# -lt 1 ] ; then - echo "$0: at least one argument needed" 1>&2 + vecho "${0##*/}: at least one argument needed" 1>&2 exit 1 fi @@ -16,7 +17,7 @@ ret=0 for x in "$@" ; do if [ -s "${x}" ] ; then install -m0644 "${x}" "${dir}" - gzip -f -9 "${dir}/${x##*/}" + ecompress "${dir}/${x##*/}" elif [ ! -e "${x}" ] ; then echo "dodoc: ${x} does not exist" 1>&2 ((++ret)) diff --git a/bin/doinfo b/bin/doinfo index 0607e8c82..d38de9be0 100755 --- a/bin/doinfo +++ b/bin/doinfo @@ -1,21 +1,15 @@ #!@BASH@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/doinfo,v 1.7 2004/10/04 13:56:50 vapier Exp $ -if [ ${#} -lt 1 ] ; then - echo "doinfo: at least one argument needed" +if [[ -z $1 ]] ; then + vecho "${0##*/}: at least one argument needed" exit 1 fi -if [ ! -d "${ED}/usr/share/info" ] ; then - install -d "${ED}/usr/share/info" + +if [[ ! -d ${ED}usr/share/info ]] ; then + install -d "${ED}usr/share/info" || exit 1 fi -for x in "$@" ; do - if [ -e "${x}" ] ; then - install -m 0644 "${x}" "${ED}/usr/share/info" - gzip -f -9 "${ED}/usr/share/info/${x##*/}" - else - echo "doinfo: ${x} does not exist" - fi -done +exec install -m0644 "$@" "${ED}usr/share/info" diff --git a/bin/ecompress b/bin/ecompress new file mode 100755 index 000000000..91172177e --- /dev/null +++ b/bin/ecompress @@ -0,0 +1,44 @@ +#!/bin/bash +# Copyright 1999-2007 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: prepman 5507 2007-01-10 04:22:27Z zmedico $ + +if [[ -z $1 ]] ; then + echo "${0##*/}: at least one argument needed" 1>&2 + exit 1 +fi + +source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh + +# setup compression stuff +PORTAGE_COMPRESS=${PORTAGE_COMPRESS:-bzip2} +if [[ -z ${PORTAGE_COMPRESS_FLAGS} ]] ; then + case ${PORTAGE_COMPRESS} in + bzip2|gzip) PORTAGE_COMPRESS_FLAGS="-9";; + esac +fi + +case $1 in + --suffix) + set -e + tmpdir="${T}"/.ecompress$$.${RANDOM} + mkdir "${tmpdir}" + cd "${tmpdir}" + # we have to fill the file enough so that there is something + # to compress as some programs will refuse to do compression + # if it cannot actually compress the file + echo {0..1000} > compressme + ${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS} compressme + suffix=$(ls compressme*) + suffix=${suffix#compressme} + cd / + rm -rf "${tmpdir}" + echo "${suffix}" + ;; + --bin) + echo "${PORTAGE_COMPRESS} ${PORTAGE_COMPRESS_FLAGS}" + ;; + *) + exec "${PORTAGE_COMPRESS}" ${PORTAGE_COMPRESS_FLAGS} "$@" + ;; +esac diff --git a/bin/ecompressdir b/bin/ecompressdir new file mode 100755 index 000000000..405f8e2f5 --- /dev/null +++ b/bin/ecompressdir @@ -0,0 +1,44 @@ +#!/bin/bash +# Copyright 1999-2007 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: prepalldocs 3483 2006-06-10 21:40:40Z genone $ + +if [[ -z $1 ]] ; then + echo "${0##*/}: at least one argument needed" 1>&2 + exit 1 +fi + +# figure out the new suffix +suffix=$(ecompress --suffix) +[[ -z ${suffix} ]] && exit 0 + +source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh + +ret=0 + +for dir in "$@" ; do + dir="${D}${dir}" + if [[ ! -d ${dir} ]] ; then + vecho "${0##*/}: ${dir#${D}} does not exist!" + continue + else + vecho "${0##*/}: $(ecompress --bin) ${dir#${D}}" + fi + + find "${dir}" -type f -print0 | xargs -0 ecompress + ((ret+=$?)) + find -L "${dir}" -type l | \ + while read brokenlink ; do + olddest=$(readlink "${brokenlink}") + newdest="${olddest}${suffix}" + if [[ -e ${newdest} ]] ; then + ln -snf "${newdest}" "${brokenlink}" + ((ret+=$?)) + else + vecho "ecompressdir: unknown broken symlink: ${brokenlink}" + ((++ret)) + fi + done +done + +exit ${ret} diff --git a/bin/emerge b/bin/emerge index c4234c2b0..75d4cb721 100755 --- a/bin/emerge +++ b/bin/emerge @@ -3858,6 +3858,8 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): print ">>> Timestamps on the server and in the local repository are the same." print ">>> Cancelling all further sync action. You are already up to date." print ">>>" + print ">>> In order to force sync, remove '%s'." % tmpservertimestampfile + print ">>>" print sys.exit(0) elif (servertimestamp != 0) and (servertimestamp < mytimestamp): @@ -3867,6 +3869,8 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): print ">>>" print ">>> SERVER OUT OF DATE: %s" % dosyncuri print ">>>" + print ">>> In order to force sync, remove '%s'." % tmpservertimestampfile + print ">>>" print elif (servertimestamp == 0) or (servertimestamp > mytimestamp): # actual sync diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index f2f54f6ba..cdc2eb7a3 100644 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -365,9 +365,7 @@ install_qa_check() { fi # Portage regenerates this on the installed system. - if [[ -f ${ED}/usr/share/info/dir.gz ]] ; then - rm -f "${ED}"/usr/share/info/dir.gz - fi + rm -f "${ED}"/usr/share/info/dir{,.gz,.bz2} if hasq multilib-strict ${FEATURES} && \ [[ -x ${EPREFIX}/usr/bin/file && -x ${EPREFIX}/usr/bin/find ]] && \ diff --git a/bin/prepalldocs b/bin/prepalldocs index b592058f6..3b830b065 100755 --- a/bin/prepalldocs +++ b/bin/prepalldocs @@ -1,33 +1,25 @@ #!@BASH@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/prepalldocs,v 1.6 2004/10/04 13:56:50 vapier Exp $ -z="`find "${ED}"/usr/share/doc \( -type f -or -type l \) -not -name "*.gz" -not -name "*.js" 2>/dev/null`" +if [[ -n $1 ]] ; then + vecho "${0##*/}: invalid usage; takes no arguments" 1>&2 +fi -for y in ${z} ; do - if [ -L "${y}" ] ; then - # Symlink ... - mylink="${y}" - linkto="`readlink "${y}"`" +cd "${ED}" +[[ -d usr/share/doc ]] || exit 0 - if [ "${linkto##*.}" != "gz" ] ; then - linkto="${linkto}.gz" - fi - if [ "${mylink##*.}" != "gz" ] ; then - mylink="${mylink}.gz" - fi +# we dont want to compress the html subdir +if [[ -d ${ED}usr/share/doc/${PF}/html ]] ; then + mv "${ED}"usr/share/doc/${PF}/html "${T}"/ecompressdir-html-backup || exit 1 +fi - echo "fixing doc symlink: ${mylink##*/}" - ln -snf "${linkto}" "${mylink}" - if [ "${y}" != "${mylink}" ] ; then - echo "removing old symlink: ${y##*/}" - rm -f "${y}" - fi - else - if [ "${y##*.}" != "gz" ] ; then - echo "gzipping doc: ${y##*/}" - gzip -f -9 "${y}" - fi - fi -done +ecompressdir /usr/share/doc +ret=$? + +if [[ -d ${T}/ecompressdir-html-backup ]] ; then + mv "${T}"/html "${ED}"/usr/share/doc/${PF}/html +fi + +exit ${ret} diff --git a/bin/prepallinfo b/bin/prepallinfo index 01e022d8e..f5ec97f42 100755 --- a/bin/prepallinfo +++ b/bin/prepallinfo @@ -3,7 +3,6 @@ # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/prepallinfo,v 1.6 2004/10/04 13:56:50 vapier Exp $ -[[ ! -d ${ED}/usr/share/info ]] && exit 0 +[[ ! -d ${ED}usr/share/info ]] && exit 0 -echo "info:" exec prepinfo diff --git a/bin/prepallman b/bin/prepallman index cfbd07619..9c59d1c6f 100755 --- a/bin/prepallman +++ b/bin/prepallman @@ -1,18 +1,15 @@ #!@BASH@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/prepallman,v 1.10 2004/10/04 13:56:50 vapier Exp $ ret=0 -echo "man:" -for x in "${ED}"/opt/*/man "${ED}"/usr/share/man "${ED}"/usr/local/man "${ED}"/usr/X11R6/man ; do - if [[ -d ${x} ]] ; then - x=${x#${ED}} - x=${x%/man} - prepman "${x}" - ((ret+=$?)) - fi -done +find "${ED}" -type d -name man > "${T}"/prepallman.filelist +while read mandir ; do + mandir=${mandir#${ED}} + prepman "${mandir%/man}" + ((ret+=$?)) +done < "${T}"/prepallman.filelist exit ${ret} diff --git a/bin/prepinfo b/bin/prepinfo index b203eaa51..9e0ff58ff 100755 --- a/bin/prepinfo +++ b/bin/prepinfo @@ -1,45 +1,27 @@ #!@BASH@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/prepinfo,v 1.6.2.1 2005/05/29 12:40:08 jstubbs Exp $ -if [ -z "$1" ] ; then - z="${ED}/usr/share/info" +if [[ -z $1 ]] ; then + infodir="${EPREFIX}/usr/share/info" else - if [ -d "${ED}$1/share/info" ] ; then - z="${ED}$1/share/info" + if [[ -d ${ED}$1/share/info ]] ; then + infodir="${EPREFIX}$1/share/info" else - z="${ED}$1/info" + infodir="${EPREFIX}$1/info" fi fi -[ ! -d "${z}" ] && exit 0 - -rm -f "${z}"/{dir,dir.info,dir.info.gz} - -for x in `find "${z}"/ -mindepth 1 -maxdepth 1 \( -type f -or -type l \) 2>/dev/null` ; do - if [ -L "${x}" ] ; then - # Symlink ... - mylink="${x}" - linkto="`readlink "${x}"`" - - if [ "${linkto##*.}" != "gz" ] ; then - linkto="${linkto}.gz" - fi - if [ "${mylink##*.}" != "gz" ] ; then - mylink="${mylink}.gz" - fi - - echo "fixing GNU info symlink: ${mylink##*/}" - ln -snf "${linkto}" "${mylink}" - if [ "${x}" != "${mylink}" ] ; then - echo "removing old symlink: ${x##*/}" - rm -f "${x}" - fi +if [[ ! -d ${ED}${infodir} ]] ; then + if [[ -n $1 ]] ; then + vecho "${0##*/}: '${infodir}' does not exist!" + exit 1 else - if [ "${x##*.}" != "gz" ] ; then - echo "gzipping GNU info page: ${x##*/}" - gzip -f -9 "${x}" - fi + exit 0 fi -done +fi + +rm -f "${ED}${infodir}"/dir{,.info}{,.gz,.bz2} + +exec ecompressdir "${infodir}" diff --git a/bin/prepman b/bin/prepman index 0ba2bd35b..8588b8d25 100755 --- a/bin/prepman +++ b/bin/prepman @@ -1,49 +1,28 @@ #!@BASH@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/bin/prepman,v 1.10.2.3 2005/05/29 12:40:08 jstubbs Exp $ if [[ -z $1 ]] ; then - z="${ED}/usr/share/man" + mandir="${ED}usr/share/man" else - z="${ED}$1/man" + mandir="${ED}$1/man" fi -if [[ ! -d ${z} ]] ; then - eqawarn "QA Notice: prepman called with non-existent dir '${z#${ED}}'" +if [[ ! -d ${mandir} ]] ; then + eqawarn "QA Notice: prepman called with non-existent dir '${mandir#${ED}}'" exit 0 fi -for x in $(find "${z}"/ -type d 2>/dev/null) ; do - for y in $(find "${x}"/ -mindepth 1 -maxdepth 1 \( -type f -or -type l \) ! -name '.keep_*' 2>/dev/null) ; do - if [[ -L ${y} ]] ; then - # Symlink ... - mylink=${y} - linkto=$(readlink "${y}") - - # Do NOT change links to directories - if [[ -d ${z}/${linkto} ]] ; then - continue - fi +shopt -s nullglob - if [[ ${linkto##*.} != "gz" ]] && [[ ${linkto##*.} != "bz2" ]] ; then - linkto="${linkto}.gz" - fi - if [[ ${mylink##*.} != "gz" ]] && [[ ${mylink##*.} != "bz2" ]] ; then - mylink="${mylink}.gz" - fi +ret=0 - echo "fixing man page symlink: ${mylink##*/}" - ln -snf "${linkto}" "${mylink}" - if [[ ${y} != "${mylink}" ]] ; then - echo "removing old symlink: ${y##*/}" - rm -f "${y}" - fi - else - if [[ ${y##*.} != "gz" ]] && [[ ${y##*.} != "bz2" ]] && [[ ! -d ${y} ]] ; then - echo "gzipping man page: ${y##*/}" - gzip -f -9 "${y}" - fi - fi - done +# compress and fixup links in each dir +for subdir in "${mandir}"/man* "${mandir}"/*/man* ; do + [[ -d ${subdir} ]] || continue # ignore files named 'man*' + ecompressdir "/${subdir#${ED}}" + ((ret+=$?)) done + +exit ${ret} diff --git a/man/make.conf.5 b/man/make.conf.5 index a7823cac6..39351fd62 100644 --- a/man/make.conf.5 +++ b/man/make.conf.5 @@ -110,6 +110,7 @@ is specified. .B EPAUSE_IGNORE Defines whether or not to ignore short pauses that occur when displaying important informational messages. This variable is unset by default. +If it is set to any value pauses are ignored. .TP \fBFEATURES\fR = \fI"sandbox ccache"\fR Defines actions portage takes by default. These options should diff --git a/pym/portage.py b/pym/portage.py index 7283286eb..5416f924f 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -1888,8 +1888,13 @@ class config: myflags = set(myflags) myflags.update(self.useforce) + # FEATURES=test should imply USE=test + if "test" in self.configlist[-1].get("FEATURES","").split(): + myflags.add("test") + usesplit = [ x for x in myflags if \ x not in self.usemask] + usesplit.sort() # Use the calculated USE flags to regenerate the USE_EXPAND flags so diff --git a/pym/portage_dep.py b/pym/portage_dep.py index c8074bb55..545884409 100644 --- a/pym/portage_dep.py +++ b/pym/portage_dep.py @@ -382,7 +382,7 @@ def isvalidatom(atom, allow_blockers=False): def isjustname(mypkg): """ - Checks to see if the depstring is only the package name + Checks to see if the depstring is only the package name (no version parts) Example usage: >>> isjustname('media-libs/test-3.0') diff --git a/pym/portage_exception.py b/pym/portage_exception.py index 0a9d8d130..95e03640d 100644 --- a/pym/portage_exception.py +++ b/pym/portage_exception.py @@ -8,7 +8,7 @@ class PortageException(Exception): def __init__(self,value): self.value = value[:] def __str__(self): - if isinstance(self.value, str): + if isinstance(self.value, basestring): return self.value else: return repr(self.value) diff --git a/pym/portage_util.py b/pym/portage_util.py index 34c4d6588..374d90616 100644 --- a/pym/portage_util.py +++ b/pym/portage_util.py @@ -178,7 +178,27 @@ def stack_lists(lists, incremental=1): return new_list.keys() def grabdict(myfilename, juststrings=0, empty=0, recursive=0, incremental=1): - """This function grabs the lines in a file, normalizes whitespace and returns lines in a dictionary""" + """ + This function grabs the lines in a file, normalizes whitespace and returns lines in a dictionary + + @param myfilename: file to process + @type myfilename: string (path) + @param juststrings: only return strings + @type juststrings: Boolean (integer) + @param empty: Ignore certain lines + @type empty: Boolean (integer) + @param recursive: Recursively grab ( support for /etc/portage/package.keywords/* and friends ) + @type recursive: Boolean (integer) + @param incremental: Append to the return list, don't overwrite + @type incremental: Boolean (integer) + @rtype: Dictionary + @returns: + 1. Returns the lines in a file in a dictionary, for example: + 'sys-apps/portage x86 amd64 ppc' + would return + { "sys-apps/portage" : [ 'x86', 'amd64', 'ppc' ] + the line syntax is key : [list of values] + """ newdict={} for x in grablines(myfilename, recursive): #the split/join thing removes leading and trailing whitespace, and converts any whitespace in the line @@ -229,7 +249,7 @@ def grablines(myfilename,recursive=0): mylines=[] if recursive and os.path.isdir(myfilename): if myfilename in ["RCS", "CVS", "SCCS"]: - continue + return mylines dirlist = os.listdir(myfilename) dirlist.sort() for f in dirlist: diff --git a/tests/portage_dep/test_dep_getcpv.py b/tests/portage_dep/test_dep_getcpv.py new file mode 100644 index 000000000..6928794a4 --- /dev/null +++ b/tests/portage_dep/test_dep_getcpv.py @@ -0,0 +1,25 @@ +# test_dep_getcpv.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_atoms.py 5525 2007-01-10 13:35:03Z antarus $ + +from unittest import TestCase +from portage_dep import dep_getcpv + +class DepGetCPV(TestCase): + """ A simple testcase for isvalidatom + """ + + def testDepGetCPV(self): + + prefix_ops = ["<", ">", "=", "~", "!", "<=", + ">=", "!=", "!<", "!>", "!~",""] + postfix_ops = [ "*", "" ] + + cpvs = ["sys-apps/portage"] + + for cpv in cpvs: + for prefix in prefix_ops: + for postfix in postfix_ops: + self.assertEqual( dep_getcpv( + prefix + cpv + postfix ), cpv ) diff --git a/tests/portage_dep/test_dep_getslot.py b/tests/portage_dep/test_dep_getslot.py new file mode 100644 index 000000000..5e18d7cd4 --- /dev/null +++ b/tests/portage_dep/test_dep_getslot.py @@ -0,0 +1,27 @@ +# test_dep_getslot.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_atoms.py 5525 2007-01-10 13:35:03Z antarus $ + +from unittest import TestCase +from portage_dep import dep_getslot + +class DepGetSlot(TestCase): + """ A simple testcase for isvalidatom + """ + + def testDepGetSlot(self): + + slot_char = ":" + slots = ( "a", "1.2", "1", "IloveVapier", None ) + cpvs = ["sys-apps/portage"] + + for cpv in cpvs: + for slot in slots: + if slot: + self.assertEqual( dep_getslot( + cpv + slot_char + slot ), slot ) + else: + self.assertEqual( dep_getslot( cpv ), slot ) + + self.assertEqual( dep_getslot( "sys-apps/portage:"), "" ) diff --git a/tests/portage_dep/test_get_operator.py b/tests/portage_dep/test_get_operator.py new file mode 100644 index 000000000..ec052d914 --- /dev/null +++ b/tests/portage_dep/test_get_operator.py @@ -0,0 +1,26 @@ +# test_match_from_list.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_atoms.py 5525 2007-01-10 13:35:03Z antarus $ + +from unittest import TestCase +from portage_dep import get_operator + +class GetOperator(TestCase): + + def testGetOperator(self): + + # get_operator does not validate operators + tests = [ ( "~", "~" ), ( "=", "=" ), ( ">", ">" ), + ( ">=", ">=" ), ( "<=", "<=" ) , ( "", None ), + ( ">~", ">" ), ("~<", "~"), ( "=~", "=" ), + ( "=>", "=" ), ("=<", "=") ] + + testCP = "sys-apps/portage" + + for test in tests: + result = get_operator( test[0] + testCP ) + self.assertEqual( result, test[1] ) + + result = get_operator( "=sys-apps/portage*" ) + self.assertEqual( result , "=*" ) diff --git a/tests/portage_dep/test_isjustname.py b/tests/portage_dep/test_isjustname.py new file mode 100644 index 000000000..a8a4e24be --- /dev/null +++ b/tests/portage_dep/test_isjustname.py @@ -0,0 +1,25 @@ +# test_isjustname.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_atoms.py 5525 2007-01-10 13:35:03Z antarus $ + +from unittest import TestCase +from portage_dep import isjustname + +class IsJustName(TestCase): + + def testIsJustName(self): + + cats = ( "", "sys-apps/", "foo/", "virtual/" ) + pkgs = ( "portage", "paludis", "pkgcore", "notARealPkg" ) + vers = ( "", "-2.0-r3", "-1.0_pre2", "-3.1b" ) + + for pkg in pkgs: + for cat in cats: + for ver in vers: + if len(ver): + self.assertFalse( isjustname( cat + pkg + ver ), + msg="isjustname(%s) is True!" % (cat + pkg + ver) ) + else: + self.assertTrue( isjustname( cat + pkg + ver ), + msg="isjustname(%s) is False!" % (cat + pkg + ver) ) diff --git a/tests/portage_dep/test_isvalidatom.py b/tests/portage_dep/test_isvalidatom.py new file mode 100644 index 000000000..84225fa78 --- /dev/null +++ b/tests/portage_dep/test_isvalidatom.py @@ -0,0 +1,36 @@ +# test_isvalidatom.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_atoms.py 5525 2007-01-10 13:35:03Z antarus $ + +from unittest import TestCase +from portage_dep import isvalidatom + +class IsValidAtom(TestCase): + """ A simple testcase for isvalidatom + """ + + def testIsValidAtom(self): + + tests = [ ( "sys-apps/portage", True ), + ( "=sys-apps/portage-2.1", True ), + ( "=sys-apps/portage-2.1*", True ), + ( ">=sys-apps/portage-2.1", True ), + ( "<=sys-apps/portage-2.1", True ), + ( ">sys-apps/portage-2.1", True ), + ( "~cate-gory/foo-1.0", False ), + ( ">~category/foo-1.0", False ), + ( "<~category/foo-1.0", False ), + ( "###cat/foo-1.0", False ), + ( "~sys-apps/portage", False ), + ( "portage", False ) ] + + for test in tests: + if test[1]: + atom_type = "valid" + else: + atom_type = "invalid" + + self.assertEqual( bool(isvalidatom( test[0] )), test[1] ) diff --git a/tests/portage_dep/test_match_from_list.py b/tests/portage_dep/test_match_from_list.py index 7afe51c5e..4526d4e31 100644 --- a/tests/portage_dep/test_match_from_list.py +++ b/tests/portage_dep/test_match_from_list.py @@ -19,15 +19,13 @@ class AtomCmpEqualGlob(TestCase): # ("=sys-fs/udev_cvs*","sys-fs/udev_cvs_pre4" ) ] for test in tests: - self.failIf( len(match_from_list( test[0], [test[1]] )) != 1, - msg="%s should match %s!" % (test[0], test[1]) ) + self.assertEqual( len(match_from_list( test[0], [test[1]] )), 1 ) def testEqualGlobFail(self): tests = [ ("=sys-apps/portage-2*", "sys-apps/portage-2.1" ), ("=sys-apps/portage-2.1*", "sys-apps/portage-2.1.2" ) ] for test in tests: try: - self.failIf( len( match_from_list( test[0], [test[1]] ) ) != 1, - msg="%s shouldn't match %s!" % (test[0], test[1]) ) + self.assertEqual( len( match_from_list( test[0], [test[1]] ) ), 1 ) except TypeError: # failure is ok here pass diff --git a/tests/portage_util/test_grabdict.py b/tests/portage_util/test_grabdict.py new file mode 100644 index 000000000..74b28ca27 --- /dev/null +++ b/tests/portage_util/test_grabdict.py @@ -0,0 +1,12 @@ +# test_grabDict.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $ + +from unittest import TestCase, TestLoader +from portage_util import grabdict + +class GrabDictTestCase(TestCase): + + def testGrabDictPass(self): + pass diff --git a/tests/portage_util/test_normalizedPath.py b/tests/portage_util/test_normalizedPath.py index 9f9a60597..3354e254e 100644 --- a/tests/portage_util/test_normalizedPath.py +++ b/tests/portage_util/test_normalizedPath.py @@ -12,5 +12,4 @@ class NormalizePathTestCase(TestCase): from portage_util import normalize_path path = "///foo/bar/baz" good = "/foo/bar/baz" - self.failUnless(normalize_path(path) == good, msg="NormalizePath(%s) failed to produce %s" % (path, good)) - + self.assertEqual(normalize_path(path), good) diff --git a/tests/portage_util/test_stackDictList.py b/tests/portage_util/test_stackDictList.py index e6442ce43..02284e8f4 100644 --- a/tests/portage_util/test_stackDictList.py +++ b/tests/portage_util/test_stackDictList.py @@ -14,6 +14,5 @@ class StackDictListTestCase(TestCase): tests.append(( {'KEYWORDS':['alpha','x86']},{'KEYWORDS':['-*']},True,{} )) tests.append(( {'KEYWORDS':['alpha','x86']},{'KEYWORDS':['-x86']},True,{'KEYWORDS':['alpha']} )) for test in tests: - self.failUnless(stack_dictlist([test[0],test[1]],incremental=test[2]) == test[3], - msg="%s and %s combined, was expecting: %s and got: %s" % (test[0],test[1],test[3], - stack_dictlist([test[0],test[1]],incremental=test[2])) ) + self.assertEqual( + stack_dictlist([test[0],test[1]],incremental=test[2]), test[3] ) diff --git a/tests/portage_util/test_stackDicts.py b/tests/portage_util/test_stackDicts.py index ac0e67ef8..98467b5a5 100644 --- a/tests/portage_util/test_stackDicts.py +++ b/tests/portage_util/test_stackDicts.py @@ -25,8 +25,7 @@ class StackDictsTestCase(TestCase): for test in tests: result = stack_dicts( test[0], test[2], test[3], test[4] ) - self.failIf( result != test[1], msg="Expected %s = %s" \ - % ( result, test[1] ) ) + self.assertEqual( result, test[1] ) def testStackDictsFail(self): @@ -35,5 +34,4 @@ class StackDictsTestCase(TestCase): False, [], False ) ] for test in tests: result = stack_dicts( test[0], test[2], test[3], test[4] ) - self.failIf( result == test[1], msg="Expected %s != %s, got \ - %s == %s!" % (result, test[1], result, test[1]) ) + self.assertNotEqual( result , test[1] ) diff --git a/tests/portage_util/test_stackLists.py b/tests/portage_util/test_stackLists.py index c69139286..c4e1e0056 100644 --- a/tests/portage_util/test_stackLists.py +++ b/tests/portage_util/test_stackLists.py @@ -17,6 +17,4 @@ class StackListsTestCase(TestCase): for test in tests: result = stack_lists( test[0], test[2] ) - self.failIf( result != test[1], - msg="Got %s != %s from stack_lists( %s, %s )" \ - % ( result, test[1], test[0], test[2] ) ) + self.assertEqual( result , test[1] ) -- 2.26.2