Skip to content

Commit

Permalink
Make code to respect PEP8 coding style
Browse files Browse the repository at this point in the history
Ignoring 'E501 line too long' error for now, it needs more work.
  • Loading branch information
Jakub Jedelsky committed Oct 13, 2016
1 parent 5ad94fe commit 4669684
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions asciinema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

__author__ = 'Marcin Kulik'
__version__ = '1.3.0'

import sys

if sys.version_info[0] < 3:
raise ImportError('Python < 3 is unsupported.')
10 changes: 7 additions & 3 deletions asciinema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class APIError(Exception):
pass


class Api:

def __init__(self, url, user, token, http_adapter=None):
Expand All @@ -28,7 +29,7 @@ def upload_asciicast(self, path):
try:
status, headers, body = self.http_adapter.post(
self.upload_url(),
files={ "asciicast": ("asciicast.json", f) },
files={"asciicast": ("asciicast.json", f)},
headers=self._headers(),
username=self.user,
password=self.token
Expand All @@ -42,13 +43,16 @@ def upload_asciicast(self, path):
return body, headers.get('Warning')

def _headers(self):
return { 'User-Agent': self._user_agent() }
return {'User-Agent': self._user_agent()}

def _user_agent(self):
os = re.sub('([^-]+)-(.*)', '\\1/\\2', platform.platform())

return 'asciinema/%s %s/%s %s' % (__version__,
platform.python_implementation(), platform.python_version(), os)
platform.python_implementation(),
platform.python_version(),
os
)

def _handle_error(self, status, body):
errors = {
Expand Down
4 changes: 2 additions & 2 deletions asciinema/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def __init__(self, api_url, api_token):

def execute(self):
url = '%s/connect/%s' % (self.api_url, self.api_token)
self.print('Open the following URL in a browser to register your API ' \
'token and assign any recorded asciicasts to your profile:\n' \
self.print('Open the following URL in a browser to register your API '
'token and assign any recorded asciicasts to your profile:\n'
'%s' % url)
1 change: 1 addition & 0 deletions asciinema/player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import time


class Player:

def play(self, asciicast, max_wait=None):
Expand Down
6 changes: 3 additions & 3 deletions asciinema/pty_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def _copy(signal_fd):
while True:
try:
rfds, wfds, xfds = select.select(fds, [], [])
except OSError as e: # Python >= 3.3
except OSError as e: # Python >= 3.3
if e.errno == errno.EINTR:
continue
except select.error as e: # Python < 3.3
except select.error as e: # Python < 3.3
if e.args[0] == 4:
continue

Expand Down Expand Up @@ -119,7 +119,7 @@ def _copy(signal_fd):
mode = tty.tcgetattr(pty.STDIN_FILENO)
tty.setraw(pty.STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
except tty.error: # This is the same as termios.error
restore = 0

_set_pty_size()
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asciinema
import sys

if sys.version_info[0] < 3:
Expand All @@ -8,9 +9,6 @@
except ImportError:
from distutils.core import setup

import asciinema


url_template = 'https://github.com/asciinema/asciinema/archive/v%s.tar.gz'
requirements = []

Expand Down
20 changes: 19 additions & 1 deletion tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def create_config(content='', env={}):

return cfg.Config(cfg.load_file([path]), env)


def test_load_config():
with tempfile.TemporaryDirectory() as dir:
config = cfg.load({'ASCIINEMA_CONFIG_HOME': dir + '/foo/bar'})
Expand All @@ -28,80 +29,97 @@ def test_load_config():
config = cfg.load({'ASCIINEMA_CONFIG_HOME': dir})
assert_equal(token, config.api_token)


def test_default_api_url():
config = create_config('')
assert_equal('https://asciinema.org', config.api_url)


def test_default_record_command():
config = create_config('')
assert_equal(None, config.record_command)


def test_default_record_max_wait():
config = create_config('')
assert_equal(None, config.record_max_wait)


def test_default_record_yes():
config = create_config('')
assert_equal(False, config.record_yes)


def test_default_record_quiet():
config = create_config('')
assert_equal(False, config.record_quiet)


def test_default_play_max_wait():
config = create_config('')
assert_equal(None, config.play_max_wait)


def test_api_url():
config = create_config("[api]\nurl = http://the/url")
assert_equal('http://the/url', config.api_url)


def test_api_url_when_override_set():
config = create_config("[api]\nurl = http://the/url", {
'ASCIINEMA_API_URL': 'http://the/url2' })
'ASCIINEMA_API_URL': 'http://the/url2'})
assert_equal('http://the/url2', config.api_url)


def test_api_token():
token = 'foo-bar-baz'
config = create_config("[api]\ntoken = %s" % token)
assert re.match(token, config.api_token)


def test_api_token_when_no_api_token_set():
config = create_config('')
with assert_raises(Exception):
config.api_token


def test_api_token_when_user_token_set():
token = 'foo-bar-baz'
config = create_config("[user]\ntoken = %s" % token)
assert re.match(token, config.api_token)


def test_api_token_when_api_token_set_and_user_token_set():
user_token = 'foo'
api_token = 'bar'
config = create_config("[user]\ntoken = %s\n[api]\ntoken = %s" % (user_token, api_token))
assert re.match(api_token, config.api_token)


def test_record_command():
command = 'bash -l'
config = create_config("[record]\ncommand = %s" % command)
assert_equal(command, config.record_command)


def test_record_max_wait():
max_wait = '2.35'
config = create_config("[record]\nmaxwait = %s" % max_wait)
assert_equal(2.35, config.record_max_wait)


def test_record_yes():
yes = 'yes'
config = create_config("[record]\nyes = %s" % yes)
assert_equal(True, config.record_yes)


def test_record_quiet():
quiet = 'yes'
config = create_config("[record]\nquiet = %s" % quiet)
assert_equal(True, config.record_quiet)


def test_play_max_wait():
max_wait = '2.35'
config = create_config("[play]\nmaxwait = %s" % max_wait)
Expand Down

0 comments on commit 4669684

Please sign in to comment.