Skip to content

Commit

Permalink
Some flake8 gardening
Browse files Browse the repository at this point in the history
  • Loading branch information
tswicegood committed Apr 21, 2015
1 parent 1d93f00 commit 836b609
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/test_install.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from .decorators import skip_if_no_mock
from .helpers import mock
patch = mock.patch if mock else None

from contextlib import contextmanager
import random
import shutil
Expand All @@ -14,6 +10,11 @@
from conda import install
from conda.install import PaddingError, binary_replace, update_prefix

from .decorators import skip_if_no_mock
from .helpers import mock

patch = mock.patch if mock else None


def generate_random_path():
return '/some/path/to/file%s' % random.randint(100, 200)
Expand Down Expand Up @@ -41,7 +42,8 @@ def test_no_extra(self):

def test_two(self):
self.assertEqual(
binary_replace(b'aaaaa\x001234aaaaacc\x00\x00', b'aaaaa', b'bbbbb'),
binary_replace(b'aaaaa\x001234aaaaacc\x00\x00', b'aaaaa',
b'bbbbb'),
b'bbbbb\x001234bbbbbcc\x00\x00')

def test_spaces(self):
Expand Down Expand Up @@ -122,7 +124,6 @@ def test_calls_func(self):
func.assert_called_with(some_path)



class rm_rf_file_and_link_TestCase(unittest.TestCase):
@contextmanager
def generate_mock_islink(self, value):
Expand Down Expand Up @@ -308,7 +309,8 @@ def test_pauses_for_same_number_of_seconds_as_max_retries(self):
mocks['rmtree'].side_effect = OSError
max_retries = random.randint(1, 10)
with self.assertRaises(OSError):
install.rm_rf(self.generate_random_path, max_retries=max_retries)
install.rm_rf(self.generate_random_path,
max_retries=max_retries)

expected = [mock.call(i) for i in range(max_retries)]
mocks['sleep'].assert_has_calls(expected)
Expand Down Expand Up @@ -357,11 +359,12 @@ def test_dispatch_to_subprocess_on_error_on_windows(self):
check_call.assert_called_with(expected_arg)

@skip_if_no_mock
def test_continues_calling_until_max_tries_on_called_process_errors_on_windows(self):
def test_calls_until_max_tries_on_called_process_errors_on_windows(self):
max_retries = random.randint(6, 10)
with self.generate_directory_mocks(on_win=True) as mocks:
mocks['rmtree'].side_effect = OSError
mocks['check_call'].side_effect = subprocess.CalledProcessError(1, "cmd")
mocks['check_call'].side_effect = subprocess.CalledProcessError(
1, "cmd")
with self.assertRaises(OSError):
install.rm_rf(generate_random_path(), max_retries=max_retries)

Expand All @@ -373,7 +376,8 @@ def test_include_onerror_failed_in_log_message_on_windows(self):
with self.generate_directory_mocks(on_win=True) as mocks:
random_path = self.generate_random_path
mocks['rmtree'].side_effect = OSError(random_path)
mocks['check_call'].side_effect = subprocess.CalledProcessError(1, "cmd")
mocks['check_call'].side_effect = subprocess.CalledProcessError(
1, "cmd")
max_retries = random.randint(1, 10)
with self.assertRaises(OSError):
install.rm_rf(random_path, max_retries=max_retries)
Expand Down

0 comments on commit 836b609

Please sign in to comment.