aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordol-sen <brian.dolbec@gmail.com>2011-09-23 23:03:26 -0700
committerdol-sen <brian.dolbec@gmail.com>2011-09-23 23:03:26 -0700
commit25ae8b28da0632ed33935e32071c9aa683814da2 (patch)
treee533ddec419bcbd808a4560ef0403f5908415026
parentpy2, py3 compatability changes so 2to3 will work correctly. (diff)
downloadlayman-25ae8b28da0632ed33935e32071c9aa683814da2.tar.gz
layman-25ae8b28da0632ed33935e32071c9aa683814da2.tar.bz2
layman-25ae8b28da0632ed33935e32071c9aa683814da2.zip
make the tests more py3 compatibile.
-rwxr-xr-xlayman/api.py6
-rw-r--r--layman/db.py33
-rw-r--r--layman/dbbase.py5
-rw-r--r--layman/makeconf.py24
-rw-r--r--layman/overlays/tar.py4
-rwxr-xr-xlayman/tests/external.py2
6 files changed, 52 insertions, 22 deletions
diff --git a/layman/api.py b/layman/api.py
index c1a0e97..3005c3f 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -396,7 +396,9 @@ class LaymanAPI(object):
>>> import os
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> cache = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> cache = os.path.join(tmpdir, 'cache')
>>> from layman.config import OptionConfig
>>> opts = {'overlays' :
... ['file://' + here + '/tests/testfiles/global-overlays.xml'],
@@ -440,6 +442,8 @@ class LaymanAPI(object):
#'priority': 10, 'feeds': [], 'irc': None, 'homepage': None}}
>>> os.unlink(filename)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
"""
try:
diff --git a/layman/db.py b/layman/db.py
index 807a740..cca257b 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -104,16 +104,17 @@ class DB(DbBase):
'''
Add an overlay to the local list of overlays.
- >>> write = os.tmpnam()
- >>> write2 = os.tmpnam()
- >>> write3 = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> write = os.path.join(tmpdir, 'installed.xml')
+ >>> write2 = os.path.join(tmpdir, 'make.conf')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> from layman.config import OptionConfig
>>> myoptions = {'installed' :
... here + '/tests/testfiles/global-overlays.xml',
... 'make_conf' : write2,
... 'nocheck' : 'yes',
- ... 'storage' : write3}
+ ... 'storage' : tmpdir}
>>> config = OptionConfig(myoptions)
>>> config.set_option('quietness', 3)
@@ -143,8 +144,8 @@ class DB(DbBase):
# >>> os.unlink(write)
>>> os.unlink(write2)
- #>>> import shutil
- # >>> shutil.rmtree(write3)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
if overlay.name not in self.overlays.keys():
@@ -183,16 +184,17 @@ class DB(DbBase):
'''
Add an overlay to the local list of overlays.
- >>> write = os.tmpnam()
- >>> write2 = os.tmpnam()
- >>> write3 = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> write = os.path.join(tmpdir, 'installed.xml')
+ >>> write2 = os.path.join(tmpdir, 'make.conf')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> from layman.config import OptionConfig
>>> myoptions = {'installed' :
... here + '/tests/testfiles/global-overlays.xml',
... 'make_conf' : write2,
... 'nocheck' : 'yes',
- ... 'storage' : write3}
+ ... 'storage' : tmpdir}
>>> config = OptionConfig(myoptions)
>>> config.set_option('quietness', 3)
@@ -230,8 +232,8 @@ class DB(DbBase):
# >>> os.unlink(write)
>>> os.unlink(write2)
- #>>> import shutil
- # >>> shutil.rmtree(write3)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
if overlay.name in self.overlays.keys():
@@ -303,8 +305,10 @@ class RemoteDB(DbBase):
'''
Copy the remote overlay list to the local cache.
+ >>> import tempfile
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> cache = os.tmpnam()
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> cache = os.path.join(tmpdir, 'cache')
>>> myoptions = {'overlays' :
... ['file://' + here + '/tests/testfiles/global-overlays.xml'],
... 'cache' : cache,
@@ -325,6 +329,9 @@ class RemoteDB(DbBase):
>>> a.overlays.keys()
[u'wrobel', u'wrobel-stable']
+
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
has_updates = False
# succeeded reset when a failure is detected
diff --git a/layman/dbbase.py b/layman/dbbase.py
index 149988b..461038b 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -195,7 +195,9 @@ class DbBase(object):
'''
Write the list of overlays to a file.
- >>> write = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> write = os.path.join(tmpdir, 'test.xml')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> from layman.config import BareConfig
>>> config = BareConfig()
@@ -209,6 +211,7 @@ class DbBase(object):
[u'wrobel-stable']
>>> os.unlink(write)
+ >>> os.rmdir(tmpdir)
'''
tree = ET.Element('repositories', version="1.0")
diff --git a/layman/makeconf.py b/layman/makeconf.py
index 9836a1a..7eca2cd 100644
--- a/layman/makeconf.py
+++ b/layman/makeconf.py
@@ -34,7 +34,9 @@ class MakeConf:
Check that an add/remove cycle does not modify the make.conf:
>>> import hashlib
- >>> write = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> write = os.path.join(tmpdir, 'make.conf')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> config = {'installed' :
... here + '/tests/testfiles/global-overlays.xml',
@@ -63,6 +65,8 @@ class MakeConf:
>>> o_md5 == n_md5
True
>>> os.unlink(write)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
my_re = re.compile('PORTDIR_OVERLAY\s*=\s*"([^"]*)"')
@@ -84,7 +88,9 @@ class MakeConf:
'''
Add an overlay to make.conf.
- >>> write = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> write = os.path.join(tmpdir, 'make.conf')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> config = {'installed' :
... here + '/tests/testfiles/global-overlays.xml',
@@ -104,6 +110,8 @@ class MakeConf:
[u'/usr/local/portage/ebuilds/testing', u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', u'/usr/local/portage/gentoo-webapps-overlay/experimental', u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
>>> os.unlink(write)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
self.overlays.append(overlay)
return self.write()
@@ -112,7 +120,9 @@ class MakeConf:
'''
Delete an overlay from make.conf.
- >>> write = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> write = os.path.join(tmpdir, 'make.conf')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> config = {'installed' :
... here + '/tests/testfiles/global-overlays.xml',
@@ -132,6 +142,8 @@ class MakeConf:
[u'/usr/local/portage/ebuilds/testing', u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', u'/usr/local/portage/gentoo-webapps-overlay/experimental', u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
>>> os.unlink(write)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
self.overlays = [i
for i in self.overlays
@@ -201,7 +213,9 @@ class MakeConf:
'''
Write the list of registered overlays to /etc/make.conf.
- >>> write = os.tmpnam()
+ >>> import tempfile
+ >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_")
+ >>> os.path.join(tmpdir, 'make.conf')
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> config = {'installed' :
... here + '/tests/testfiles/global-overlays.xml',
@@ -221,6 +235,8 @@ class MakeConf:
[u'/usr/local/portage/ebuilds/testing', u'/usr/local/portage/ebuilds/stable', u'/usr/local/portage/kolab2', u'/usr/local/portage/gentoo-webapps-overlay/experimental', u'/usr/local/portage/gentoo-webapps-overlay/production-ready']
>>> os.unlink(write)
+ >>> import shutil
+ >>> shutil.rmtree(tmpdir)
'''
def prio_sort(a, b):
'''Sort by priority.'''
diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
index 546c134..5d66acc 100644
--- a/layman/overlays/tar.py
+++ b/layman/overlays/tar.py
@@ -59,8 +59,8 @@ class TarOverlay(OverlaySource):
>>> repo[:] = [repo_name, desc, owner, source, subpath]
>>> from layman.config import BareConfig
>>> config = BareConfig()
- >>> testdir = os.tmpnam()
- >>> os.mkdir(testdir)
+ >>> import tempfile
+ >>> testdir = tempfile.mkdtemp(prefix="laymantmp_")
>>> from layman.overlays.overlay import Overlay
>>> a = Overlay(config, repo)
>>> config['output'].set_colorize(False)
diff --git a/layman/tests/external.py b/layman/tests/external.py
index e5e8c4e..00e4a82 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -54,7 +54,7 @@ class FormatSubpathCategory(unittest.TestCase):
# Read, write, re-read, compare
os1 = DbBase(config, [filename1])
- filename2 = os.tmpnam()
+ filename2 = tempfile.mkstemp()[1]
os1.write(filename2)
os2 = DbBase(config, [filename2])
os.unlink(filename2)