Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Merge branch 'fix-issue-52'
Browse files Browse the repository at this point in the history
  • Loading branch information
JMSwag committed Feb 5, 2017
2 parents 05bad45 + 8651478 commit 0ad301e
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 34 deletions.
1 change: 1 addition & 0 deletions .python-version
@@ -1,3 +1,4 @@
2.7.13
3.3.3
3.4.3
3.5.1
9 changes: 8 additions & 1 deletion docs/changelog.md
@@ -1,9 +1,16 @@
# Changelog

## v2.3.2 - Master
## v2.3.3 - Master
####* This version is not yet released and is under active development.


## v2.3.2 - 2017/02/04

###Fixed

- Calling certain cli commands


## v2.3.1 - 2017/02/04

###Fixed
Expand Down
13 changes: 9 additions & 4 deletions pyupdater/cli/__init__.py
Expand Up @@ -87,15 +87,20 @@ def _real_main(args, namespace_test_helper=None): # pragma: no cover

# Dispatch the passed in command to its respective function in
# pyupdater.cli.commands
def _dispatch_command(args, pyi_args):
def _dispatch_command(args, pyi_args=None, test=False):
# Turns collect-debug-info into collect_debug_info
cmd = args.command.replace('-', '_')
cmd_str = "_cmd_" + args.command.replace('-', '_')
try:
getattr(commands, cmd)(args, pyi_args)
cmd = getattr(commands, cmd_str)
# We are just making sure we can load the function
if test:
return True
cmd(args, pyi_args)
except AttributeError:
# This should only get hit by misconfigured tests.
# "Should" being the key word here :)
log.error('Unknown Command')
log.error('Unknown Command: %s', cmd_str)
return False


def main(args=None): # pragma: no cover
Expand Down
26 changes: 13 additions & 13 deletions pyupdater/cli/commands.py
Expand Up @@ -43,7 +43,7 @@ def check_repo(exit_on_error=False):


# Archive an external asset
def archive(*args):
def _cmd_archive(*args):
check_repo(exit_on_error=True)

ns = args[0]
Expand All @@ -65,7 +65,7 @@ def archive(*args):


# Will build and archive an exe from a python script file
def build(*args):
def _cmd_build(*args):
check_repo(exit_on_error=True)

ns = args[0]
Expand All @@ -75,7 +75,7 @@ def build(*args):


# Get permission before deleting PyUpdater repo.
def clean(*args): # pragma: no cover
def _cmd_clean(*args): # pragma: no cover
ns = args[0]
if ns.yes is True:
_clean()
Expand Down Expand Up @@ -113,7 +113,7 @@ def _clean(*args):
# Just a note: We don't allow changing the app name as this could
# cause issues with updates if not used carefully. If really need
# this value can be changed in the .pyupdater/config.pyu file.
def config(*args): # pragma: no cover
def _cmd_settings(*args): # pragma: no cover
check_repo(exit_on_error=True)

ns = args[0]
Expand Down Expand Up @@ -160,7 +160,7 @@ def config(*args): # pragma: no cover


# Initialize PyUpdater repo
def init(*args): # pragma: no cover
def _cmd_init(*args): # pragma: no cover
if not os.path.exists(os.path.join(settings.CONFIG_DATA_FOLDER,
settings.CONFIG_FILE_USER)):
# Load a basic config.
Expand All @@ -185,7 +185,7 @@ def init(*args): # pragma: no cover


# We create and import keys with this puppy.
def keys(*args): # pragma: no cover
def _cmd_keys(*args): # pragma: no cover
check = check_repo()

ns = args[0]
Expand Down Expand Up @@ -243,7 +243,7 @@ def keys(*args): # pragma: no cover
# Create a spec_file and place it in the cwd.
# This will be used when the application being build goes a little
# beyond the basics. This is good!
def make_spec(*args):
def _cmd_make_spec(*args):
check_repo(exit_on_error=True)

ns = args[0]
Expand All @@ -254,7 +254,7 @@ def make_spec(*args):

# The pkg command will move, gather meta-data & sign all
# packages within the pyu-data folder
def pkg(*args):
def _cmd_pkg(*args):
check_repo(exit_on_error=True)

ns = args[0]
Expand Down Expand Up @@ -283,12 +283,12 @@ def pkg(*args):
# I wanted to make the commands uniform to enable the usage of
# _dispatch_command in pyupdater.cli
def upload_debug_info(*args):
collect_debug_info(*args)
_cmd_collect_debug_info(*args)
# End ToDo


# Uploads the debug logs to a private github gist
def collect_debug_info(*args): # pragma: no cover
def _cmd_collect_debug_info(*args): # pragma: no cover
log.info('Starting log export')

# A helper function that adds the filename & data to the
Expand Down Expand Up @@ -361,7 +361,7 @@ def _upload(data):


# Show list of installed upload plugins
def plugins(*args):
def _cmd_plugins(*args):
plug_mgr = PluginManager({})
# Doing some basic formatting. Design help here would be appreciated.
# By the way I just want to thank all the contributors and bug submitters.
Expand All @@ -374,7 +374,7 @@ def plugins(*args):


# Upload the assets with the requested upload plugin
def upload(*args): # pragma: no cover
def _cmd_upload(*args): # pragma: no cover
check_repo(exit_on_error=True)

ns = args[0]
Expand Down Expand Up @@ -413,5 +413,5 @@ def upload(*args): # pragma: no cover


# Print the version of PyUpdater to the console.
def version(*args):
def _cmd_version(*args):
print('PyUpdater {}'.format(__version__))
84 changes: 69 additions & 15 deletions tests/test_cli.py
Expand Up @@ -29,11 +29,11 @@

import pytest

from pyupdater.cli import commands
from pyupdater.cli import commands, _dispatch_command
from pyupdater.cli.options import (add_build_parser, add_clean_parser,
add_keys_parser, add_make_spec_parser,
add_package_parser, make_subparser)

add_package_parser, add_upload_parser,
make_subparser)

commands.TEST = True

Expand Down Expand Up @@ -62,10 +62,51 @@ def __getattribute__(self, name):
return None


namespace_helper = NamespaceHelper()
@pytest.mark.usefixtures('cleandir')
class TestCommandDispatch(object):

def test_build(self):
assert _dispatch_command(NamespaceHelper(command='build'),
test=True) is True

@pytest.mark.usefixtures('cleandir', 'parser', 'pyu')
def test_clean(self):
assert _dispatch_command(NamespaceHelper(command='clean'),
test=True) is True

def test_settings(self):
assert _dispatch_command(NamespaceHelper(command='settings'),
test=True) is True

def test_init(self):
assert _dispatch_command(NamespaceHelper(command='init'),
test=True) is True

def test_keys(self):
assert _dispatch_command(NamespaceHelper(command='keys'),
test=True) is True

def test_make_spec(self):
assert _dispatch_command(NamespaceHelper(command='make-spec'),
test=True) is True

def test_pkg(self):
assert _dispatch_command(NamespaceHelper(command='pkg'),
test=True) is True

def test_collect_debug_info(self):
assert _dispatch_command(NamespaceHelper(command='collect-debug-info'),
test=True) is True

def test_upload(self):
assert _dispatch_command(NamespaceHelper(command='upload'),
test=True) is True

def test_version(self):
assert _dispatch_command(NamespaceHelper(command='version'),
test=True) is True


@pytest.mark.usefixtures('cleandir')
class TestBuilder(object):

def test_build_no_options(self, parser):
Expand All @@ -83,7 +124,7 @@ def test_build_no_arguments(self, parser, pyu):
f.write('from __futute__ import print_function\n')
f.write('print("Hello, World!")')
opts, other = parser.parse_known_args(['build', 'app.py'])
commands.build(opts, other)
commands._cmd_build(opts, other)


@pytest.mark.usefixtures('cleandir', 'parser')
Expand All @@ -102,7 +143,7 @@ def test_execution(self, parser):
os.mkdir(update_folder)
os.mkdir(data_folder)
args, other = parser.parse_known_args(['clean', '-y'])
commands.clean(args)
commands._cmd_clean(args)
assert not os.path.exists(update_folder)
assert not os.path.exists(data_folder)

Expand All @@ -112,7 +153,7 @@ def test_execution_no_clean(self, parser):
subparser = make_subparser(parser)
add_clean_parser(subparser)
args, other = parser.parse_known_args(['clean', '-y'])
commands.clean(args)
commands._cmd_clean(args)
assert not os.path.exists(update_folder)
assert not os.path.exists(data_folder)

Expand All @@ -126,8 +167,7 @@ def test_no_options(self, parser):
assert parser.parse_known_args(['keys'])

def test_create_keys(self):
namespace_helper.reload(command='keys', create=True)
commands.keys(namespace_helper)
commands._cmd_keys(NamespaceHelper(command='keys', create=True))
assert os.path.exists('keypack.pyu')


Expand All @@ -142,7 +182,7 @@ def test_deprecated_opts(self, parser, pyu):
f.write('print "Hello World"')
opts, other = parser.parse_known_args(['make-spec', '-F',
'--app-version=0.1.0', 'app.py'])
commands.make_spec(opts, other)
commands._cmd_make_spec(opts, other)

def test_execution(self, parser, pyu):
pyu.setup()
Expand All @@ -152,17 +192,31 @@ def test_execution(self, parser, pyu):
f.write('print "Hello World"')
opts, other = parser.parse_known_args(['make-spec', '-F',
'app.py'])
commands.make_spec(opts, other)
commands._cmd_make_spec(opts, other)


@pytest.mark.usefixtures('cleandir', 'parser', 'pyu')
@pytest.mark.usefixtures('cleandir')
class TestPkg(object):

def test_execution(self, parser, pyu):
def test_pkg_execution(self, parser, pyu):
subparser = make_subparser(parser)
add_package_parser(subparser)
pyu.update_config(pyu.config)
pyu.setup()
cmd = ['pkg', '-P', '-S']
opts, other = parser.parse_known_args(cmd)
commands.pkg(opts)
commands._cmd_pkg(opts)


# @pytest.mark.usefixtures('cleandir')
# class TestUpload(object):

# def test_upload_execution(self, parser, pyu):
# subparser = make_subparser(parser)
# add_upload_parser(subparser)
# pyu.update_config(pyu.config)
# pyu.setup()
# cmd = ['upload', '-h']
# opts, other = parser.parse_known_args(cmd)
# with pytest.raises(SystemExit):
# commands._cmd_upload(opts)
2 changes: 1 addition & 1 deletion tests/test_pyupdater.py
Expand Up @@ -37,7 +37,7 @@
from pyupdater import PyUpdater
from tconfig import TConfig

AUTO_UPDATE_PAUSE = 25
AUTO_UPDATE_PAUSE = 30
if sys.platform == 'win32':
AUTO_UPDATE_PAUSE += 10

Expand Down

0 comments on commit 0ad301e

Please sign in to comment.