Skip to content

Commit

Permalink
Fix tests on big-endian systems (#3125)
Browse files Browse the repository at this point in the history
* Fix tests on big-endian systems

* PEP 8
  • Loading branch information
ginggs authored and shoyer committed Jul 15, 2019
1 parent 3ceb038 commit 3c05a20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3140,7 +3140,9 @@ def test_to_and_from_dict(self):
expected_no_data = expected.copy()
del expected_no_data['data']
del expected_no_data['coords']['x']['data']
expected_no_data['coords']['x'].update({'dtype': '<U1', 'shape': (2,)})
endiantype = '<U1' if sys.byteorder == 'little' else '>U1'
expected_no_data['coords']['x'].update({'dtype': endiantype,
'shape': (2,)})
expected_no_data.update({'dtype': 'float64', 'shape': (2, 3)})
actual_no_data = array.to_dict(data=False)
assert expected_no_data == actual_no_data
Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3460,7 +3460,8 @@ def test_to_and_from_dict(self):
del expected_no_data['coords']['t']['data']
del expected_no_data['data_vars']['a']['data']
del expected_no_data['data_vars']['b']['data']
expected_no_data['coords']['t'].update({'dtype': '<U1',
endiantype = '<U1' if sys.byteorder == 'little' else '>U1'
expected_no_data['coords']['t'].update({'dtype': endiantype,
'shape': (10,)})
expected_no_data['data_vars']['a'].update({'dtype': 'float64',
'shape': (10,)})
Expand Down
15 changes: 9 additions & 6 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from textwrap import dedent
import sys

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -204,6 +205,7 @@ def test_diff_array_repr(self):
'label': ('x', np.array([1, 2], dtype='int64'))},
attrs={'units': 'kg'})

byteorder = '<' if sys.byteorder == 'little' else '>'
expected = dedent("""\
Left and right DataArray objects are not identical
Differing dimensions:
Expand All @@ -215,8 +217,8 @@ def test_diff_array_repr(self):
R
array([1, 2], dtype=int64)
Differing coordinates:
L * x (x) <U1 'a' 'b'
R * x (x) <U1 'a' 'c'
L * x (x) %cU1 'a' 'b'
R * x (x) %cU1 'a' 'c'
Coordinates only on the left object:
* y (y) int64 1 2 3
Coordinates only on the right object:
Expand All @@ -225,7 +227,7 @@ def test_diff_array_repr(self):
L units: m
R units: kg
Attributes only on the left object:
description: desc""")
description: desc""" % (byteorder, byteorder))

actual = formatting.diff_array_repr(da_a, da_b, 'identical')
try:
Expand Down Expand Up @@ -277,13 +279,14 @@ def test_diff_dataset_repr(self):
attrs={'units': 'kg'}
)

byteorder = '<' if sys.byteorder == 'little' else '>'
expected = dedent("""\
Left and right Dataset objects are not identical
Differing dimensions:
(x: 2, y: 3) != (x: 2)
Differing coordinates:
L * x (x) <U1 'a' 'b'
R * x (x) <U1 'a' 'c'
L * x (x) %cU1 'a' 'b'
R * x (x) %cU1 'a' 'c'
source: 0
Coordinates only on the left object:
* y (y) int64 1 2 3
Expand All @@ -298,7 +301,7 @@ def test_diff_dataset_repr(self):
L units: m
R units: kg
Attributes only on the left object:
description: desc""")
description: desc""" % (byteorder, byteorder))

actual = formatting.diff_dataset_repr(ds_a, ds_b, 'identical')
assert actual == expected
Expand Down

0 comments on commit 3c05a20

Please sign in to comment.