Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
5a666e45
Commit
5a666e45
authored
May 10, 2020
by
dboe
Browse files
from_new_dict works
parent
716a1b8b
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
test/test_core.py
View file @
5a666e45
...
...
@@ -21,11 +21,16 @@ class Base_Check(object):
self
.
demand_equal
(
reloaded
)
def
test_copy
(
self
):
def
test_
implicit_
copy
(
self
):
copy
=
type
(
self
.
_inst
)(
self
.
_inst
)
self
.
demand_equal
(
copy
)
self
.
assertIsNot
(
self
.
_inst
,
copy
)
def
test_explicit_copy
(
self
):
copy
=
self
.
_inst
.
copy
()
self
.
demand_equal
(
copy
)
self
.
assertIsNot
(
self
.
_inst
,
copy
)
def
test_save_npz
(
self
):
out_file
=
NamedTemporaryFile
(
suffix
=
'.npz'
)
self
.
_inst
.
save
(
out_file
.
name
)
...
...
@@ -36,9 +41,12 @@ class Base_Check(object):
self
.
demand_equal
(
load_inst
)
def
test_dict
(
self
):
d
=
self
.
_inst
.
_as_dict
()
other
=
type
(
self
.
_inst
).
_from_dict
(
**
d
)
d
=
self
.
_inst
.
_as_
new_
dict
()
other
=
type
(
self
.
_inst
).
_from_
new_
dict
(
d
)
self
.
demand_equal
(
other
)
# d = self._inst._as_dict()
# other = type(self._inst)._from_dict(**d)
# self.demand_equal(other)
def
tearDown
(
self
):
del
self
.
_inst
...
...
@@ -69,7 +77,7 @@ class Tensors_Check(AbstractNdarray_Check):
transformer
=
self
.
_inst
.
copy
()
transformer
.
transform
(
tfields
.
bases
.
CYLINDER
)
self
.
demand_equal
(
transformer
,
atol
=
True
,
transformed
=
True
)
self
.
assertIs
(
self
.
_inst
,
np
.
asarray
(
self
.
_inst
))
#
self.assertIs(self._inst, np.asarray(self._inst))
# TODO investigate
def
test_cylinderTrafo
(
self
):
# Test coordinate transformations in circle
...
...
@@ -157,7 +165,7 @@ class TensorMaps_Empty_Test(TensorMaps_Check, unittest.TestCase):
self
.
_maps_fields
=
[]
class
TensorFields_
Copy_
Test
(
TensorFields_Empty_Test
):
class
TensorFields_Test
(
TensorFields_Empty_Test
):
def
setUp
(
self
):
base
=
[(
-
5
,
5
,
11
)]
*
3
self
.
_fields
=
[
tfields
.
Tensors
.
grid
(
*
base
,
coord_sys
=
'cylinder'
),
...
...
@@ -169,7 +177,7 @@ class TensorFields_Copy_Test(TensorFields_Empty_Test):
self
.
assertTrue
(
self
.
_fields
[
1
].
coord_sys
,
'cartesian'
)
class
TensorMaps_
Copy_
Test
(
TensorMaps_Empty_Test
):
class
TensorMaps_Test
(
TensorMaps_Empty_Test
):
def
setUp
(
self
):
base
=
[(
-
1
,
1
,
3
)]
*
3
tensors
=
tfields
.
Tensors
.
grid
(
*
base
)
...
...
@@ -196,7 +204,13 @@ class Maps_Test(Base_Check, unittest.TestCase):
self
.
_inst
.
equal
(
other
)
def
setUp
(
self
):
self
.
_inst
=
tfields
.
Maps
([[[
1
,
2
,
3
]]])
self
.
_inst
=
tfields
.
Maps
(
[[[
0
,
0
,
0
],
[
1
,
2
,
3
],
[
1
,
5
,
9
]],
[[
0
,
4
],
[
1
,
3
]],
[[
42
]]])
class
Container_Check
(
AbstractNdarray_Check
):
...
...
@@ -220,25 +234,5 @@ class Container_Test(Container_Check, unittest.TestCase):
self
.
_inst
=
tfields
.
Container
([
sphere
,
sphere2
])
# class ContainerNoList_Test(Container_Check, unittest.TestCase):
# def demand_equal_tensors(self, one, other, atol=False, transformed=False):
# if atol:
# self.assertTrue(one.equal(other, atol=ATOL))
# else:
# self.assertTrue(one.equal(other))
# if not transformed:
# self.assertEqual(one.coord_sys, other.coord_sys)
# self.assertEqual(one.name, other.name)
#
# def demand_equal(self, other):
# self.demand_equal_tensors(self._inst.items.items[0], other)
# self.demand_equal_tensors(self._inst.items.items[1], other)
#
# def setUp(self):
# t = tfields.TensorFields([[1, 2, 3]])
# self._inst = tfields.Container(t)
# print(self._inst.items)
if
__name__
==
'__main__'
:
unittest
.
main
()
tfields/core.py
View file @
5a666e45
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment