* [gentoo-commits] proj/layman:master commit in: layman/overlays/, layman/, layman/tests/
@ 2011-09-24 6:07 Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2011-09-24 6:07 UTC (permalink / raw
To: gentoo-commits
commit: 25ae8b28da0632ed33935e32071c9aa683814da2
Author: dol-sen <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sat Sep 24 06:03:26 2011 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sat Sep 24 06:03:26 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=25ae8b28
make the tests more py3 compatibile.
---
layman/api.py | 6 +++++-
layman/db.py | 33 ++++++++++++++++++++-------------
layman/dbbase.py | 5 ++++-
layman/makeconf.py | 24 ++++++++++++++++++++----
layman/overlays/tar.py | 4 ++--
layman/tests/external.py | 2 +-
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)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/layman:gsoc2014 commit in: layman/overlays/, layman/, layman/tests/
@ 2014-06-16 3:37 Brian Dolbec
2014-06-16 3:40 ` [gentoo-commits] proj/layman:master " Brian Dolbec
0 siblings, 1 reply; 3+ messages in thread
From: Brian Dolbec @ 2014-06-16 3:37 UTC (permalink / raw
To: gentoo-commits
commit: b47238ef6ef407c7c07a94b885b7243a089c797f
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 12 21:17:02 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Jun 15 00:36:41 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=b47238ef
Implements the "with" syntax to open files
---
layman/dbbase.py | 10 +++++-----
layman/makeconf.py | 16 +++++-----------
layman/overlays/tar.py | 9 +++++----
layman/remotedb.py | 14 ++++++--------
layman/reposconf.py | 6 ++++--
layman/tests/external.py | 5 ++---
6 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/layman/dbbase.py b/layman/dbbase.py
index 92d5cf9..e17e8f3 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -131,8 +131,8 @@ class DbBase(object):
'''Read the overlay definition file.'''
try:
- df = fileopen(path, 'r')
- document = df.read()
+ with fileopen(path, 'r') as df:
+ document = df.read()
except Exception as error:
if not self.ignore_init_read_errors:
@@ -235,9 +235,9 @@ class DbBase(object):
indent(tree)
tree = ET.ElementTree(tree)
try:
- f = fileopen(path, 'w')
- tree.write(f, encoding=_UNICODE)
- f.close()
+ with fileopen(path, 'w') as f:
+ tree.write(f, encoding=_UNICODE)
+
except Exception as error:
raise Exception('Failed to write to local overlays file: '
+ path + '\nError was:\n' + str(error))
diff --git a/layman/makeconf.py b/layman/makeconf.py
index f1eba09..15ad537 100644
--- a/layman/makeconf.py
+++ b/layman/makeconf.py
@@ -22,7 +22,7 @@ import codecs
import re
from layman.utils import path
-from layman.compatibility import cmp_to_key
+from layman.compatibility import cmp_to_key, fileopen
#===============================================================================
#
@@ -276,11 +276,8 @@ class ConfigHandler:
return False
try:
- make_conf = codecs.open(self.path, 'w', 'utf-8')
-
- make_conf.write(content)
-
- make_conf.close()
+ with fileopen(self.path, 'w') as make_conf:
+ make_conf.write(content)
except Exception as error:
self.output.error('MakeConf: ConfigHandler.write(); Failed to write "'\
@@ -293,11 +290,8 @@ class ConfigHandler:
Returns the content of the /var/lib/layman/make.conf file.
'''
try:
- make_conf = codecs.open(self.path, 'r', 'utf-8')
-
- self.data = make_conf.read()
-
- make_conf.close()
+ with fileopen(self.path, 'r') as make_conf:
+ self.data = make_conf.read()
except Exception as error:
self.output.error('ConfigHandler: content(); Failed to read "'\
diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
index acbeece..fc15c56 100644
--- a/layman/overlays/tar.py
+++ b/layman/overlays/tar.py
@@ -34,8 +34,9 @@ import tempfile
import xml.etree.ElementTree as ET # Python 2.5
-from layman.utils import path
+from layman.compatibility import fileopen
from layman.overlays.source import OverlaySource, require_supported
+from layman.utils import path
from layman.version import VERSION
from sslfetch.connections import Connector
@@ -120,9 +121,9 @@ class TarOverlay(OverlaySource):
pkg = path([base, self.parent.name + ext])
try:
- out_file = open(pkg, 'w+b')
- out_file.write(tar)
- out_file.close()
+ with fileopen(pkg, 'w+b') as out_file:
+ out_file.write(tar)
+
except Exception as error:
raise Exception('Failed to store tar package in '
+ pkg + '\nError was:' + str(error))
diff --git a/layman/remotedb.py b/layman/remotedb.py
index f883799..79f4ec6 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -17,7 +17,6 @@
'''Handles different storage files.'''
from __future__ import unicode_literals
-from __future__ import with_statement
__version__ = "$Id: db.py 309 2007-04-09 16:23:38Z wrobel $"
@@ -261,8 +260,9 @@ class RemoteDB(DbBase):
if url_timestamp != timestamp:
self.output.debug('RemoteDB._fetch_file() opening file', 2)
# Fetch the remote list
- with open(filepath) as connection:
+ with fileopen(filepath) as connection:
olist = connection.read()
+
else:
self.output.info('Remote list already up to date: %s'
% url, 4)
@@ -324,14 +324,12 @@ class RemoteDB(DbBase):
def write_cache(olist, mpath, tpath=None, timestamp=None):
has_updates = False
try:
- out_file = fileopen(mpath, 'w')
- out_file.write(olist)
- out_file.close()
+ with fileopen(mpath, 'w') as out_file:
+ out_file.write(olist)
if timestamp is not None and tpath is not None:
- out_file = fileopen(tpath, 'w')
- out_file.write(str(timestamp))
- out_file.close()
+ with fileopen(tpath, 'w') as out_file:
+ out_file.write(str(timestamp))
has_updates = True
diff --git a/layman/reposconf.py b/layman/reposconf.py
index a7a0166..c550a13 100644
--- a/layman/reposconf.py
+++ b/layman/reposconf.py
@@ -24,7 +24,8 @@ except:
# Import for Python2
import ConfigParser
-from layman.utils import path
+from layman.compatibility import fileopen
+from layman.utils import path
class ConfigHandler:
@@ -117,8 +118,9 @@ class ConfigHandler:
@return boolean: represents a successful write.
'''
try:
- with open(self.path, 'w') as laymanconf:
+ with fileopen(self.path, 'w') as laymanconf:
self.repo_conf.write(laymanconf)
+
return True
except IOError as error:
self.output.error('ReposConf: ConfigHandler.write(); Failed to write "'\
diff --git a/layman/tests/external.py b/layman/tests/external.py
index 3505eeb..82825e2 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -99,9 +99,8 @@ class TarAddRemoveSync(unittest.TestCase):
""" % { 'temp_tarball_url':urllib.pathname2url(temp_tarball_path),
'repo_name':repo_name}
(fd, temp_collection_path) = tempfile.mkstemp()
- f = os.fdopen(fd, 'w')
- f.write(xml_text)
- f.close()
+ with os.fdopen(fd, 'w') as f:
+ f.write(xml_text)
# Make playground directory
temp_dir_path = tempfile.mkdtemp()
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/layman:master commit in: layman/overlays/, layman/, layman/tests/
2014-06-16 3:37 [gentoo-commits] proj/layman:gsoc2014 " Brian Dolbec
@ 2014-06-16 3:40 ` Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2014-06-16 3:40 UTC (permalink / raw
To: gentoo-commits
commit: b47238ef6ef407c7c07a94b885b7243a089c797f
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 12 21:17:02 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sun Jun 15 00:36:41 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=b47238ef
Implements the "with" syntax to open files
---
layman/dbbase.py | 10 +++++-----
layman/makeconf.py | 16 +++++-----------
layman/overlays/tar.py | 9 +++++----
layman/remotedb.py | 14 ++++++--------
layman/reposconf.py | 6 ++++--
layman/tests/external.py | 5 ++---
6 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/layman/dbbase.py b/layman/dbbase.py
index 92d5cf9..e17e8f3 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -131,8 +131,8 @@ class DbBase(object):
'''Read the overlay definition file.'''
try:
- df = fileopen(path, 'r')
- document = df.read()
+ with fileopen(path, 'r') as df:
+ document = df.read()
except Exception as error:
if not self.ignore_init_read_errors:
@@ -235,9 +235,9 @@ class DbBase(object):
indent(tree)
tree = ET.ElementTree(tree)
try:
- f = fileopen(path, 'w')
- tree.write(f, encoding=_UNICODE)
- f.close()
+ with fileopen(path, 'w') as f:
+ tree.write(f, encoding=_UNICODE)
+
except Exception as error:
raise Exception('Failed to write to local overlays file: '
+ path + '\nError was:\n' + str(error))
diff --git a/layman/makeconf.py b/layman/makeconf.py
index f1eba09..15ad537 100644
--- a/layman/makeconf.py
+++ b/layman/makeconf.py
@@ -22,7 +22,7 @@ import codecs
import re
from layman.utils import path
-from layman.compatibility import cmp_to_key
+from layman.compatibility import cmp_to_key, fileopen
#===============================================================================
#
@@ -276,11 +276,8 @@ class ConfigHandler:
return False
try:
- make_conf = codecs.open(self.path, 'w', 'utf-8')
-
- make_conf.write(content)
-
- make_conf.close()
+ with fileopen(self.path, 'w') as make_conf:
+ make_conf.write(content)
except Exception as error:
self.output.error('MakeConf: ConfigHandler.write(); Failed to write "'\
@@ -293,11 +290,8 @@ class ConfigHandler:
Returns the content of the /var/lib/layman/make.conf file.
'''
try:
- make_conf = codecs.open(self.path, 'r', 'utf-8')
-
- self.data = make_conf.read()
-
- make_conf.close()
+ with fileopen(self.path, 'r') as make_conf:
+ self.data = make_conf.read()
except Exception as error:
self.output.error('ConfigHandler: content(); Failed to read "'\
diff --git a/layman/overlays/tar.py b/layman/overlays/tar.py
index acbeece..fc15c56 100644
--- a/layman/overlays/tar.py
+++ b/layman/overlays/tar.py
@@ -34,8 +34,9 @@ import tempfile
import xml.etree.ElementTree as ET # Python 2.5
-from layman.utils import path
+from layman.compatibility import fileopen
from layman.overlays.source import OverlaySource, require_supported
+from layman.utils import path
from layman.version import VERSION
from sslfetch.connections import Connector
@@ -120,9 +121,9 @@ class TarOverlay(OverlaySource):
pkg = path([base, self.parent.name + ext])
try:
- out_file = open(pkg, 'w+b')
- out_file.write(tar)
- out_file.close()
+ with fileopen(pkg, 'w+b') as out_file:
+ out_file.write(tar)
+
except Exception as error:
raise Exception('Failed to store tar package in '
+ pkg + '\nError was:' + str(error))
diff --git a/layman/remotedb.py b/layman/remotedb.py
index f883799..79f4ec6 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -17,7 +17,6 @@
'''Handles different storage files.'''
from __future__ import unicode_literals
-from __future__ import with_statement
__version__ = "$Id: db.py 309 2007-04-09 16:23:38Z wrobel $"
@@ -261,8 +260,9 @@ class RemoteDB(DbBase):
if url_timestamp != timestamp:
self.output.debug('RemoteDB._fetch_file() opening file', 2)
# Fetch the remote list
- with open(filepath) as connection:
+ with fileopen(filepath) as connection:
olist = connection.read()
+
else:
self.output.info('Remote list already up to date: %s'
% url, 4)
@@ -324,14 +324,12 @@ class RemoteDB(DbBase):
def write_cache(olist, mpath, tpath=None, timestamp=None):
has_updates = False
try:
- out_file = fileopen(mpath, 'w')
- out_file.write(olist)
- out_file.close()
+ with fileopen(mpath, 'w') as out_file:
+ out_file.write(olist)
if timestamp is not None and tpath is not None:
- out_file = fileopen(tpath, 'w')
- out_file.write(str(timestamp))
- out_file.close()
+ with fileopen(tpath, 'w') as out_file:
+ out_file.write(str(timestamp))
has_updates = True
diff --git a/layman/reposconf.py b/layman/reposconf.py
index a7a0166..c550a13 100644
--- a/layman/reposconf.py
+++ b/layman/reposconf.py
@@ -24,7 +24,8 @@ except:
# Import for Python2
import ConfigParser
-from layman.utils import path
+from layman.compatibility import fileopen
+from layman.utils import path
class ConfigHandler:
@@ -117,8 +118,9 @@ class ConfigHandler:
@return boolean: represents a successful write.
'''
try:
- with open(self.path, 'w') as laymanconf:
+ with fileopen(self.path, 'w') as laymanconf:
self.repo_conf.write(laymanconf)
+
return True
except IOError as error:
self.output.error('ReposConf: ConfigHandler.write(); Failed to write "'\
diff --git a/layman/tests/external.py b/layman/tests/external.py
index 3505eeb..82825e2 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -99,9 +99,8 @@ class TarAddRemoveSync(unittest.TestCase):
""" % { 'temp_tarball_url':urllib.pathname2url(temp_tarball_path),
'repo_name':repo_name}
(fd, temp_collection_path) = tempfile.mkstemp()
- f = os.fdopen(fd, 'w')
- f.write(xml_text)
- f.close()
+ with os.fdopen(fd, 'w') as f:
+ f.write(xml_text)
# Make playground directory
temp_dir_path = tempfile.mkdtemp()
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/layman:master commit in: layman/overlays/, layman/, layman/tests/
@ 2011-07-23 6:45 Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2011-07-23 6:45 UTC (permalink / raw
To: gentoo-commits
commit: 7fa3a45f35d8571e384f8648aed49384de0d8a4d
Author: dol-sen <brian.dolbec <AT> gmail <DOT> com>
AuthorDate: Sat Jul 23 06:43:29 2011 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sat Jul 23 06:43:29 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=7fa3a45f
update all tests to pass
---
layman/db.py | 60 +++++++++++++++++++++++++-------------------
layman/dbbase.py | 32 ++++++++++++++---------
layman/overlays/overlay.py | 18 +++++++++----
layman/tests/dtest.py | 1 +
layman/tests/external.py | 18 ++++++++-----
5 files changed, 78 insertions(+), 51 deletions(-)
diff --git a/layman/db.py b/layman/db.py
index 747eb4b..bb6fd81 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -78,24 +78,27 @@ class DB(DbBase):
>>> write2 = os.tmpnam()
>>> write3 = os.tmpnam()
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> config = {'local_list' :
+ >>> from layman.config import OptionConfig
+ >>> myoptions = {'local_list' :
... here + '/tests/testfiles/global-overlays.xml',
... 'make_conf' : write2,
- ... 'nocheck' : True,
- ... 'storage' : write3,
- ... 'quietness':3}
+ ... 'nocheck' : 'yes',
+ ... 'storage' : write3}
- >>> here = os.path.dirname(os.path.realpath(__file__))
+ >>> config = OptionConfig(myoptions)
+ >>> config.set_option('quietness', 3)
>>> a = DB(config)
- >>> config['local_list'] = write
+ >>> config.set_option('local_list', write)
>>> b = DB(config)
- >>> OUT.color_off()
+ >>> config['output'].set_colorize(False)
>>> m = MakeConf(config, b.overlays)
>>> m.path = write2
- >>> m.write()
+ >>> success = m.write()
+ >>> success
+ True
- Commented out since it needs network access:
+ # Commented out since it needs network access:
# >>> b.add(a.select('wrobel-stable')) #doctest: +ELLIPSIS
# * Running command "/usr/bin/rsync -rlptDvz --progress --delete --delete-after --timeout=180 --exclude="distfiles/*" --exclude="local/*" --exclude="packages/*" "rsync://gunnarwrobel.de/wrobel-stable/*" "/tmp/file.../wrobel-stable""...
@@ -107,11 +110,10 @@ class DB(DbBase):
# >>> [i.name for i in m.overlays] #doctest: +ELLIPSIS
# [u'wrobel-stable']
-
# >>> os.unlink(write)
>>> os.unlink(write2)
- >>> import shutil
+ #>>> import shutil
# >>> shutil.rmtree(write3)
'''
@@ -155,25 +157,28 @@ class DB(DbBase):
>>> write2 = os.tmpnam()
>>> write3 = os.tmpnam()
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> config = {'local_list' :
+ >>> from layman.config import OptionConfig
+ >>> myoptions = {'local_list' :
... here + '/tests/testfiles/global-overlays.xml',
... 'make_conf' : write2,
- ... 'nocheck' : True,
- ... 'storage' : write3,
- ... 'quietness':3}
+ ... 'nocheck' : 'yes',
+ ... 'storage' : write3}
- >>> here = os.path.dirname(os.path.realpath(__file__))
+ >>> config = OptionConfig(myoptions)
+ >>> config.set_option('quietness', 3)
>>> a = DB(config)
- >>> config['local_list'] = write
+ >>> config.set_option('local_list', write)
>>> b = DB(config)
- >>> .color_off()
+ >>> config['output'].set_colorize(False)
>>> m = MakeConf(config, b.overlays)
>>> m.path = here + '/tests/testfiles/make.conf'
>>> m.read()
+ True
>>> m.path = write2
>>> m.write()
+ True
# >>> b.add(a.select('wrobel-stable')) #doctest: +ELLIPSIS
# * Running command "/usr/bin/rsync -rlptDvz --progress --delete --delete-after --timeout=180 --exclude="distfiles/*" --exclude="local/*" --exclude="packages/*" "rsync://gunnarwrobel.de/wrobel-stable/*" "/tmp/file.../wrobel-stable""...
@@ -194,8 +199,8 @@ class DB(DbBase):
# >>> os.unlink(write)
>>> os.unlink(write2)
- >>> import shutil
+ #>>> import shutil
# >>> shutil.rmtree(write3)
'''
@@ -270,20 +275,23 @@ class RemoteDB(DbBase):
>>> here = os.path.dirname(os.path.realpath(__file__))
>>> cache = os.tmpnam()
- >>> config = {'overlays' :
- ... 'file://' + here + '/tests/testfiles/global-overlays.xml',
+ >>> myoptions = {'overlays' :
+ ... ['file://' + here + '/tests/testfiles/global-overlays.xml'],
... 'cache' : cache,
- ... 'nocheck' : True,
- ... 'proxy' : None,
- ... 'quietness':3}
+ ... 'nocheck' : 'yes',
+ ... 'proxy' : None}
+ >>> from layman.config import OptionConfig
+ >>> config = OptionConfig(myoptions)
+ >>> config.set_option('quietness', 3)
>>> a = RemoteDB(config)
>>> a.cache()
- >>> b = open(a.path(config['overlays']))
+ True
+ >>> b = open(a.filepath(config['overlays'])+'.xml')
>>> b.readlines()[24]
' A collection of ebuilds from Gunnar Wrobel [wrobel@gentoo.org].\\n'
>>> b.close()
- >>> os.unlink(a.path(config['overlays']))
+ >>> os.unlink(a.filepath(config['overlays'])+'.xml')
>>> a.overlays.keys()
[u'wrobel', u'wrobel-stable']
diff --git a/layman/dbbase.py b/layman/dbbase.py
index 48199a6..b6b0e6d 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -136,8 +136,10 @@ class DbBase:
Read an xml list of overlays (adding to and potentially overwriting existing entries)
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> config = {'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
- >>> a = DbBase([here + '/tests/testfiles/global-overlays.xml', ], config)
+ >>> from layman.output import Message
+ >>> output = Message()
+ >>> config = {'output': output, 'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
+ >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', ])
>>> a.overlays.keys()
[u'wrobel', u'wrobel-stable']
@@ -193,12 +195,14 @@ class DbBase:
>>> write = os.tmpnam()
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> config = {'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
- >>> a = DbBase([here + '/tests/testfiles/global-overlays.xml', ], config)
- >>> b = DbBase([write,], dict())
+ >>> from layman.config import BareConfig
+ >>> config = BareConfig()
+ >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', ])
+ >>> from layman.output import Message
+ >>> b = DbBase({"output": Message() }, [write,])
>>> b.overlays['wrobel-stable'] = a.overlays['wrobel-stable']
>>> b.write(write)
- >>> c = DbBase([write,], dict())
+ >>> c = DbBase({"output": Message() }, [write,])
>>> c.overlays.keys()
[u'wrobel-stable']
@@ -225,8 +229,10 @@ class DbBase:
Select an overlay from the list.
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> config = {'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
- >>> a = DbBase([here + '/tests/testfiles/global-overlays.xml', ], config)
+ >>> from layman.output import Message
+ >>> output = Message()
+ >>> config = {'output': output, 'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
+ >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', ])
>>> list(a.select('wrobel-stable').source_uris())
[u'rsync://gunnarwrobel.de/wrobel-stable']
'''
@@ -239,9 +245,11 @@ class DbBase:
List all overlays.
>>> here = os.path.dirname(os.path.realpath(__file__))
- >>> config = {'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
- >>> a = DbBase([here + '/tests/testfiles/global-overlays.xml', ], config)
- >>> for i in a.list(True):
+ >>> from layman.output import Message
+ >>> output = Message()
+ >>> config = {'output': output, 'svn_command': '/usr/bin/svn', 'rsync_command':'/usr/bin/rsync'}
+ >>> a = DbBase(config, [here + '/tests/testfiles/global-overlays.xml', ])
+ >>> for i in a.list(verbose=True):
... print(i[0])
wrobel
~~~~~~
@@ -264,7 +272,7 @@ class DbBase:
A collection of ebuilds from Gunnar Wrobel [wrobel@gentoo.org].
<BLANKLINE>
- >>> for i in a.list(False, 80):
+ >>> for i in a.list(verbose=False, width=80):
... print(i[0])
wrobel [Subversion] (https://o.g.o/svn/dev/wrobel )
wrobel-stable [Rsync ] (rsync://gunnarwrobel.de/wrobel-stable)
diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index d57fe22..60d57d4 100644
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -80,7 +80,9 @@ class Overlay(object):
>>> import xml.etree.ElementTree as ET # Python 2.5
>>> document =ET.parse(here + '/../tests/testfiles/global-overlays.xml')
>>> overlays = document.findall('overlay') + document.findall('repo')
- >>> a = Overlay(overlays[0], dict())
+ >>> from layman.output import Message
+ >>> output = Message()
+ >>> a = Overlay({'output': output}, overlays[0])
>>> a.name
u'wrobel'
>>> a.is_official()
@@ -93,7 +95,7 @@ class Overlay(object):
u'Test'
>>> a.priority
10
- >>> b = Overlay(overlays[1], dict())
+ >>> b = Overlay({'output': output}, overlays[1])
>>> b.is_official()
False
'''
@@ -433,8 +435,10 @@ class Overlay(object):
>>> import xml.etree.ElementTree as ET # Python 2.5
>>> document =ET.parse(here + '/../tests/testfiles/global-overlays.xml')
>>> overlays = document.findall('overlay') + document.findall('repo')
- >>> a = Overlay(overlays[0], dict())
- >>> print str(a)
+ >>> from layman.output import Message
+ >>> output = Message()
+ >>> a = Overlay({'output': output}, overlays[0])
+ >>> print a.get_infostr()
wrobel
~~~~~~
Source : https://overlays.gentoo.org/svn/dev/wrobel
@@ -506,9 +510,11 @@ class Overlay(object):
>>> import xml.etree.ElementTree as ET # Python 2.5
>>> document =ET.parse(here + '/../tests/testfiles/global-overlays.xml')
>>> overlays = document.findall('repo') + document.findall('overlay')
- >>> a = Overlay(overlays[0], dict())
+ >>> from layman.output import Message
+ >>> output = Message()
+ >>> a = Overlay({'output': output}, overlays[0])
>>> print a.short_list(80)
- wrobel [Subversion] (https://o.g.o/svn/dev/wrobel )
+ wrobel [Subversion] (https://o.g.o/svn/dev/wrobel )
'''
name = pad(self.name, 25)
diff --git a/layman/tests/dtest.py b/layman/tests/dtest.py
index 15e0900..4bf3437 100755
--- a/layman/tests/dtest.py
+++ b/layman/tests/dtest.py
@@ -69,6 +69,7 @@ def test_suite():
return unittest.TestSuite((
#doctest.DocTestSuite(layman.api),
doctest.DocTestSuite(layman.config),
+ doctest.DocTestSuite(layman.argsparser),
doctest.DocTestSuite(layman.db),
doctest.DocTestSuite(layman.dbbase),
doctest.DocTestSuite(layman.utils),
diff --git a/layman/tests/external.py b/layman/tests/external.py
index 3c23373..e5e8c4e 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -21,6 +21,8 @@ import tempfile
import shutil
import urllib
from layman.dbbase import DbBase
+from layman.output import Message
+from layman.config import BareConfig
from warnings import filterwarnings, resetwarnings
HERE = os.path.dirname(os.path.realpath(__file__))
@@ -28,9 +30,9 @@ HERE = os.path.dirname(os.path.realpath(__file__))
class Unicode(unittest.TestCase):
def _overlays_bug(self, number):
- config = {}
+ config = BareConfig()
filename = os.path.join(HERE, 'testfiles', 'overlays_bug_%d.xml' % number)
- o = DbBase([filename], config)
+ o = DbBase(config, [filename])
for verbose in (True, False):
for t in o.list(verbose=verbose):
print t[0]
@@ -45,15 +47,16 @@ class Unicode(unittest.TestCase):
class FormatSubpathCategory(unittest.TestCase):
def _run(self, number):
- config = {}
+ #config = {'output': Message()}
+ config = BareConfig()
filename1 = os.path.join(HERE, 'testfiles',
'subpath-%d.xml' % number)
# Read, write, re-read, compare
- os1 = DbBase([filename1], config)
+ os1 = DbBase(config, [filename1])
filename2 = os.tmpnam()
os1.write(filename2)
- os2 = DbBase([filename2], config)
+ os2 = DbBase(config, [filename2])
os.unlink(filename2)
self.assertTrue(os1 == os2)
@@ -103,8 +106,9 @@ class TarAddRemoveSync(unittest.TestCase):
temp_dir_path = tempfile.mkdtemp()
# Make DB from it
- config = {'tar_command':'/bin/tar'}
- db = DbBase([temp_collection_path], config)
+ #config = {'output': Message(), 'tar_command':'/bin/tar'}
+ config = BareConfig()
+ db = DbBase(config, [temp_collection_path])
specific_overlay_path = os.path.join(temp_dir_path, repo_name)
o = db.select('tar-test-overlay')
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-16 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-24 6:07 [gentoo-commits] proj/layman:master commit in: layman/overlays/, layman/, layman/tests/ Brian Dolbec
-- strict thread matches above, loose matches on Subject: below --
2014-06-16 3:37 [gentoo-commits] proj/layman:gsoc2014 " Brian Dolbec
2014-06-16 3:40 ` [gentoo-commits] proj/layman:master " Brian Dolbec
2011-07-23 6:45 Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox