Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests on big-endian systems #3125

Merged
merged 2 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3125,7 +3125,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 @@ -3445,7 +3445,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