From 720a62faf6229ba83ca79439d0914dc68d78bb42 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Thu, 11 Aug 2016 01:18:41 -0700 Subject: [PATCH] Add pytest-xdist to the travis build. --- .travis.yml | 4 ++-- rtv/terminal.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80cc630..d0b3804 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,11 @@ python: - "3.4" - "3.5" before_install: - - pip install coveralls pytest coverage mock pylint vcrpy + - pip install coveralls pytest pytest-xdist coverage mock pylint vcrpy install: - pip install . script: - pylint --rcfile .pylintrc -E rtv/ - - coverage run -m py.test -v + - coverage run -m py.test -v -n auto after_success: - coveralls diff --git a/rtv/terminal.py b/rtv/terminal.py index 4cad9e1..f600c09 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -7,13 +7,12 @@ import time import codecs import curses import logging -import tempfile import webbrowser import subprocess import curses.ascii from curses import textpad -from datetime import datetime from contextlib import contextmanager +from tempfile import NamedTemporaryFile import six from kitchen.text.display import textual_width_chop @@ -540,8 +539,10 @@ class Terminal(object): text (str): The text that the user entered into the editor. """ - filename = 'rtv_{:%Y%m%d_%H%M%S}.txt'.format(datetime.now()) - filepath = os.path.join(tempfile.gettempdir(), filename) + with NamedTemporaryFile(prefix='rtv_', suffix='.txt', delete=False) as fp: + # Create a tempory file and grab the name, but close immediately so + # we can re-open using the right encoding + filepath = fp.name with codecs.open(filepath, 'w', 'utf-8') as fp: fp.write(data) @@ -568,7 +569,7 @@ class Terminal(object): # All exceptions will cause the file to *not* be removed, but these # ones should also be swallowed _logger.info('Caught TemporaryFileError') - self.show_notification('Post saved as: %s', filepath) + self.show_notification('Post saved as: %s' % filepath) else: # If no errors occurred, try to remove the file try: