From d82721cf173acbbc27129152bb51d2b1d7a7c528 Mon Sep 17 00:00:00 2001 From: Eduardo Schettino Date: Sat, 11 Jul 2015 03:52:59 +0800 Subject: [PATCH] CLN: cleanup up platform / python version checks. fix GB10151 --- bench/bench_sparse.py | 3 +-- pandas/computation/tests/test_eval.py | 4 +--- pandas/io/tests/test_json/test_ujson.py | 2 +- pandas/io/tests/test_parsers.py | 2 +- pandas/io/tests/test_pytables.py | 5 ++--- pandas/tests/test_common.py | 3 +-- pandas/tests/test_format.py | 6 +++--- pandas/tests/test_index.py | 2 +- pandas/tools/tests/test_util.py | 3 +-- pandas/tseries/tests/test_daterange.py | 8 +------- pandas/tseries/tests/test_timeseries.py | 10 +--------- pandas/tseries/tests/test_timezones.py | 6 ++---- pandas/util/testing.py | 13 ++++++++++++- 13 files changed, 28 insertions(+), 39 deletions(-) diff --git a/bench/bench_sparse.py b/bench/bench_sparse.py index 7dc2db05cfe20..0aa705118d970 100644 --- a/bench/bench_sparse.py +++ b/bench/bench_sparse.py @@ -1,4 +1,3 @@ -import sys import numpy as np from pandas import * @@ -30,7 +29,7 @@ s1_dense = s1.to_dense() s2_dense = s2.to_dense() -if 'linux' in sys.platform: +if compat.is_platform_linux(): pth = '/home/wesm/code/pandas/example' else: pth = '/Users/wesm/code/pandas/example' diff --git a/pandas/computation/tests/test_eval.py b/pandas/computation/tests/test_eval.py index 8f82e2eaea711..61bc40e34b5a3 100644 --- a/pandas/computation/tests/test_eval.py +++ b/pandas/computation/tests/test_eval.py @@ -163,9 +163,7 @@ def test_floor_division(self): self.check_floor_division(lhs, '//', rhs) def test_pow(self): - import platform - if platform.system() == 'Windows': - raise nose.SkipTest('not testing pow on Windows') + tm._skip_if_windows() # odd failure on win32 platform, so skip for lhs, rhs in product(self.lhses, self.rhses): diff --git a/pandas/io/tests/test_json/test_ujson.py b/pandas/io/tests/test_json/test_ujson.py index fcd5515419537..303ecdbf0ec6e 100644 --- a/pandas/io/tests/test_json/test_ujson.py +++ b/pandas/io/tests/test_json/test_ujson.py @@ -36,7 +36,7 @@ def _skip_if_python_ver(skip_major, skip_minor=None): raise nose.SkipTest("skipping Python version %d.%d" % (major, minor)) -json_unicode = (json.dumps if sys.version_info[0] >= 3 +json_unicode = (json.dumps if compat.PY3 else partial(json.dumps, encoding="utf-8")) class UltraJSONTests(TestCase): diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 3dae9f383db8f..e6aee76df4e74 100755 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -163,7 +163,7 @@ def test_empty_string(self): def test_read_csv(self): if not compat.PY3: - if 'win' in sys.platform: + if compat.is_platform_windows(): prefix = u("file:///") else: prefix = u("file://") diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index e9c39127d1032..ace3e4c5e18dd 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -2067,9 +2067,8 @@ def test_store_timezone(self): # GH2852 # issue storing datetime.date with a timezone as it resets when read back in a new timezone - import platform - if platform.system() == "Windows": - raise nose.SkipTest("timezone setting not supported on windows") + # timezone setting not supported on windows + tm._skip_if_windows() import datetime import time diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 9ac7083289461..f7121fa54a5b1 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -2,7 +2,6 @@ import collections from datetime import datetime import re -import sys import nose from nose.tools import assert_equal @@ -447,7 +446,7 @@ def __hash__(self): # old-style classes in Python 2 don't appear hashable to # collections.Hashable but also seem to support hash() by default - if sys.version_info[0] == 2: + if compat.PY2: class OldStyleClass(): pass c = OldStyleClass() diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index b38dba5008905..b733cacc01e05 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -990,7 +990,7 @@ def test_to_html_truncate(self):

20 rows × 20 columns

'''.format(div_style) - if sys.version_info[0] < 3: + if compat.PY2: expected = expected.decode('utf-8') self.assertEqual(result, expected) @@ -1106,7 +1106,7 @@ def test_to_html_truncate_multi_index(self):

8 rows × 8 columns

'''.format(div_style) - if sys.version_info[0] < 3: + if compat.PY2: expected = expected.decode('utf-8') self.assertEqual(result, expected) @@ -1216,7 +1216,7 @@ def test_to_html_truncate_multi_index_sparse_off(self):

8 rows × 8 columns

'''.format(div_style) - if sys.version_info[0] < 3: + if compat.PY2: expected = expected.decode('utf-8') self.assertEqual(result, expected) diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index a69db34bdd2df..32f20337c109a 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -1022,7 +1022,7 @@ def test_format(self): # windows has different precision on datetime.datetime.now (it doesn't include us # since the default for Timestamp shows these but Index formating does not # we are skipping - if not is_platform_windows: + if not is_platform_windows(): formatted = index.format() expected = [str(index[0])] self.assertEqual(formatted, expected) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 9480ea7ee5bf8..1adf47e946a96 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -43,8 +43,7 @@ def setUpClass(cls): if not cls.locales: raise nose.SkipTest("No locales found") - if os.name == 'nt': # we're on windows - raise nose.SkipTest("Running on Windows") + tm._skip_if_windows() @classmethod def tearDownClass(cls): diff --git a/pandas/tseries/tests/test_daterange.py b/pandas/tseries/tests/test_daterange.py index ee30b188bce4d..86e0f7162c545 100644 --- a/pandas/tseries/tests/test_daterange.py +++ b/pandas/tseries/tests/test_daterange.py @@ -1,7 +1,6 @@ from datetime import datetime from pandas.compat import range import nose -import sys import numpy as np from pandas.core.index import Index @@ -16,11 +15,6 @@ import pandas.util.testing as tm -def _skip_if_windows_python_3(): - if sys.version_info > (3,) and sys.platform == 'win32': - raise nose.SkipTest("not used on python 3/win32") - - def eq_gen_range(kwargs, expected): rng = generate_range(**kwargs) assert(np.array_equal(list(rng), expected)) @@ -459,7 +453,7 @@ def test_month_range_union_tz_pytz(self): early_dr.union(late_dr) def test_month_range_union_tz_dateutil(self): - _skip_if_windows_python_3() + tm._skip_if_windows_python_3() tm._skip_if_no_dateutil() from pandas.tslib import _dateutil_gettz as timezone tz = timezone('US/Eastern') diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 48fe84ccfb0d5..d167982b5b0bd 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -46,14 +46,6 @@ def _skip_if_has_locale(): if lang is not None: raise nose.SkipTest("Specific locale is set {0}".format(lang)) -def _skip_if_windows_python_3(): - if sys.version_info > (3,) and sys.platform == 'win32': - raise nose.SkipTest("not used on python 3/win32") - -def _skip_if_not_windows_python_3(): - if sys.version_info < (3,) or sys.platform != 'win32': - raise nose.SkipTest("only run on python 3/win32") - class TestTimeSeriesDuplicates(tm.TestCase): _multiprocess_can_split_ = True @@ -417,7 +409,7 @@ def test_timestamp_to_datetime_explicit_pytz(self): self.assertEqual(stamp.tzinfo, dtval.tzinfo) def test_timestamp_to_datetime_explicit_dateutil(self): - _skip_if_windows_python_3() + tm._skip_if_windows_python_3() tm._skip_if_no_dateutil() from pandas.tslib import _dateutil_gettz as gettz rng = date_range('20090415', '20090519', diff --git a/pandas/tseries/tests/test_timezones.py b/pandas/tseries/tests/test_timezones.py index c5107046a3f1c..aa655efc08ca5 100644 --- a/pandas/tseries/tests/test_timezones.py +++ b/pandas/tseries/tests/test_timezones.py @@ -1,7 +1,5 @@ # pylint: disable-msg=E1101,W0612 from datetime import datetime, timedelta, tzinfo, date -import sys -import os import nose import numpy as np @@ -837,8 +835,8 @@ def localize(self, tz, x): return x.replace(tzinfo=tz) def test_utc_with_system_utc(self): - if sys.platform == 'win32': - raise nose.SkipTest('Skipped on win32 due to dateutil bug.') + # Skipped on win32 due to dateutil bug + tm._skip_if_windows() from pandas.tslib import maybe_get_tz diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 8bb6741f73475..3096bddcf6247 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -28,7 +28,7 @@ import pandas.compat as compat from pandas.compat import( filter, map, zip, range, unichr, lrange, lmap, lzip, u, callable, Counter, - raise_with_traceback, httplib + raise_with_traceback, httplib, is_platform_windows ) from pandas.computation import expressions as expr @@ -223,6 +223,17 @@ def _skip_if_no_dateutil(): raise nose.SkipTest("dateutil not installed") +def _skip_if_windows_python_3(): + if compat.PY3 and is_platform_windows(): + import nose + raise nose.SkipTest("not used on python 3/win32") + +def _skip_if_windows(): + if is_platform_windows(): + import nose + raise nose.SkipTest("Running on Windows") + + def _skip_if_no_cday(): from pandas.core.datetools import cday if cday is None: