Skip to content

Commit

Permalink
Modules tar and zip promoted into main package
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Sep 4, 2012
1 parent 4b05068 commit d778df6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pgxnclient/archive.py
Expand Up @@ -23,12 +23,12 @@ def from_file(filename):
"""
# Get the metadata from an archive file
if filename.endswith('.zip'):
from pgxnclient.utils.zip import ZipArchive
from pgxnclient.zip import ZipArchive
return ZipArchive(filename)
else:
# Tar files have many naming variants. Let's not
# guess them.
from pgxnclient.utils.tar import TarArchive
from pgxnclient.tar import TarArchive
return TarArchive(filename)


Expand Down
3 changes: 2 additions & 1 deletion pgxnclient/tar.py
Expand Up @@ -14,7 +14,8 @@
from pgxnclient.archive import Archive

import logging
logger = logging.getLogger('pgxnclient.utils.tar')
logger = logging.getLogger('pgxnclient.tar')


class TarArchive(Archive):
"""Handle .tar archives"""
Expand Down
28 changes: 14 additions & 14 deletions pgxnclient/tests/test_commands.py
Expand Up @@ -324,10 +324,10 @@ def assertCallArgs(self, pattern, args):

# With mock patching a method seems tricky: looks there's no way to get to
# 'self' as the mock method is unbound.
from pgxnclient.utils.tar import TarArchive
from pgxnclient.tar import TarArchive
TarArchive.unpack_orig = TarArchive.unpack

from pgxnclient.utils.zip import ZipArchive
from pgxnclient.zip import ZipArchive
ZipArchive.unpack_orig = ZipArchive.unpack

class InstallTestCase(unittest.TestCase, Assertions):
Expand Down Expand Up @@ -417,7 +417,7 @@ def test_install_sudo(self):
self.assertCallArgs(['gksudo', '-d', 'hello world', self.make],
self.mock_popen.call_args_list[1][0][0][:4])

@patch('pgxnclient.utils.tar.TarArchive.unpack')
@patch('pgxnclient.tar.TarArchive.unpack')
def test_install_local_tar(self, mock_unpack):
fn = get_test_filename('foobar-0.42.1.tar.gz')
mock_unpack.side_effect = TarArchive(fn).unpack_orig
Expand All @@ -435,7 +435,7 @@ def test_install_local_tar(self, mock_unpack):
tmpdir, = mock_unpack.call_args[0]
self.assertEqual(make_cwd, os.path.join(tmpdir, 'foobar-0.42.1'))

@patch('pgxnclient.utils.zip.ZipArchive.unpack')
@patch('pgxnclient.zip.ZipArchive.unpack')
def test_install_local_zip(self, mock_unpack):
fn = get_test_filename('foobar-0.42.1.zip')
mock_unpack.side_effect = ZipArchive(fn).unpack_orig
Expand All @@ -458,7 +458,7 @@ def test_install_local_dir(self):

tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)

from pgxnclient.cli import main
Expand Down Expand Up @@ -605,7 +605,7 @@ def test_check_psql_options(self, mock_get):
args = self.mock_popen.call_args[0][0]
self.assertEqual('somewhere', args[args.index('--host') + 1])

@patch('pgxnclient.utils.zip.ZipArchive.unpack')
@patch('pgxnclient.zip.ZipArchive.unpack')
@patch('pgxnclient.api.get_file')
def test_load_local_zip(self, mock_get, mock_unpack):
mock_get.side_effect = lambda *args: self.fail('network invoked')
Expand All @@ -621,7 +621,7 @@ def test_load_local_zip(self, mock_get, mock_unpack):
self.assertEquals(communicate.call_args[0][0],
'CREATE EXTENSION foobar;')

@patch('pgxnclient.utils.tar.TarArchive.unpack')
@patch('pgxnclient.tar.TarArchive.unpack')
@patch('pgxnclient.api.get_file')
def test_load_local_tar(self, mock_get, mock_unpack):
mock_get.side_effect = lambda *args: self.fail('network invoked')
Expand All @@ -643,7 +643,7 @@ def test_load_local_dir(self, mock_get):

tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)

from pgxnclient.cli import main
Expand All @@ -661,7 +661,7 @@ def test_load_local_dir(self, mock_get):
def test_load_extensions_order(self):
tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)
shutil.copyfile(
get_test_filename('META-manyext.json'),
Expand All @@ -688,7 +688,7 @@ def test_load_extensions_order(self):
def test_unload_extensions_order(self):
tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)
shutil.copyfile(
get_test_filename('META-manyext.json'),
Expand All @@ -715,7 +715,7 @@ def test_unload_extensions_order(self):
def test_load_list(self):
tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)
shutil.copyfile(
get_test_filename('META-manyext.json'),
Expand All @@ -738,7 +738,7 @@ def test_load_list(self):
def test_unload_list(self):
tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)
shutil.copyfile(
get_test_filename('META-manyext.json'),
Expand All @@ -761,7 +761,7 @@ def test_unload_list(self):
def test_load_missing(self):
tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)
shutil.copyfile(
get_test_filename('META-manyext.json'),
Expand All @@ -779,7 +779,7 @@ def test_load_missing(self):
def test_unload_missing(self):
tdir = tempfile.mkdtemp()
try:
from pgxnclient.utils.zip import unpack
from pgxnclient.zip import unpack
dir = unpack(get_test_filename('foobar-0.42.1.zip'), tdir)
shutil.copyfile(
get_test_filename('META-manyext.json'),
Expand Down
3 changes: 2 additions & 1 deletion pgxnclient/zip.py
Expand Up @@ -16,7 +16,8 @@
from pgxnclient.archive import Archive

import logging
logger = logging.getLogger('pgxnclient.utils.zip')
logger = logging.getLogger('pgxnclient.zip')


class ZipArchive(Archive):
"""Handle .zip archives"""
Expand Down

0 comments on commit d778df6

Please sign in to comment.