From 37df78a8e0510834e43efe877e762754d0c779b6 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 10 Apr 2021 09:35:10 +0200 Subject: [PATCH] don't show progress bar for empty iterations --- python/damask/util.py | 2 +- .../reference/Result/get/test_get[1].pbz2 | Bin 48 -> 46 bytes .../reference/Result/get/test_get[5].pbz2 | Bin 48 -> 46 bytes .../reference/Result/place/test_place[1].pbz2 | Bin 48 -> 46 bytes .../reference/Result/place/test_place[5].pbz2 | Bin 48 -> 46 bytes python/tests/test_Result.py | 33 +++++++++++------- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/python/damask/util.py b/python/damask/util.py index 3fe30320a..b519fb15e 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -137,7 +137,7 @@ def show_progress(iterable,N_iter=None,prefix='',bar_length=50): Character length of bar. Defaults to 50. """ - if N_iter == 1 or (hasattr(iterable,'__len__') and len(iterable) == 1): + if N_iter in [0,1] or (hasattr(iterable,'__len__') and len(iterable) <= 1): for item in iterable: yield item else: diff --git a/python/tests/reference/Result/get/test_get[1].pbz2 b/python/tests/reference/Result/get/test_get[1].pbz2 index c1963d4eaf5b3c808081454a4553c95097f00396..088e68f70a76de1221804f0d88b96e86d7953727 100644 GIT binary patch literal 46 zcmZ>Y%CIzaj8qGb6z0;t&cMKU#eoG#GB7$YC@?6_$}sj7w~0L|^3ch_M`L{q0QX`G AhX4Qo literal 48 zcmZ>Y%CIzaj8qGbd?Z-;kb!~m!UGl{$-v~mz`~%wpxD+pi#fQkTqU@blTT56o&W$p C8Vo%E diff --git a/python/tests/reference/Result/get/test_get[5].pbz2 b/python/tests/reference/Result/get/test_get[5].pbz2 index c1963d4eaf5b3c808081454a4553c95097f00396..088e68f70a76de1221804f0d88b96e86d7953727 100644 GIT binary patch literal 46 zcmZ>Y%CIzaj8qGb6z0;t&cMKU#eoG#GB7$YC@?6_$}sj7w~0L|^3ch_M`L{q0QX`G AhX4Qo literal 48 zcmZ>Y%CIzaj8qGbd?Z-;kb!~m!UGl{$-v~mz`~%wpxD+pi#fQkTqU@blTT56o&W$p C8Vo%E diff --git a/python/tests/reference/Result/place/test_place[1].pbz2 b/python/tests/reference/Result/place/test_place[1].pbz2 index c1963d4eaf5b3c808081454a4553c95097f00396..088e68f70a76de1221804f0d88b96e86d7953727 100644 GIT binary patch literal 46 zcmZ>Y%CIzaj8qGb6z0;t&cMKU#eoG#GB7$YC@?6_$}sj7w~0L|^3ch_M`L{q0QX`G AhX4Qo literal 48 zcmZ>Y%CIzaj8qGbd?Z-;kb!~m!UGl{$-v~mz`~%wpxD+pi#fQkTqU@blTT56o&W$p C8Vo%E diff --git a/python/tests/reference/Result/place/test_place[5].pbz2 b/python/tests/reference/Result/place/test_place[5].pbz2 index c1963d4eaf5b3c808081454a4553c95097f00396..088e68f70a76de1221804f0d88b96e86d7953727 100644 GIT binary patch literal 46 zcmZ>Y%CIzaj8qGb6z0;t&cMKU#eoG#GB7$YC@?6_$}sj7w~0L|^3ch_M`L{q0QX`G AhX4Qo literal 48 zcmZ>Y%CIzaj8qGbd?Z-;kb!~m!UGl{$-v~mz`~%wpxD+pi#fQkTqU@blTT56o&W$p C8Vo%E diff --git a/python/tests/test_Result.py b/python/tests/test_Result.py index a659ce056..0c34e7989 100644 --- a/python/tests/test_Result.py +++ b/python/tests/test_Result.py @@ -65,14 +65,17 @@ class TestResult: assert dict_equal(a,default.view('times','*').get('F')) assert dict_equal(a,default.view('times',default.times_in_range(0.0,np.inf)).get('F')) - @pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations + @pytest.mark.parametrize('what',['increments','times','phases','fields']) # ToDo: discuss homogenizations def test_view_none(self,default,what): - a = default.view(what,False).get('F') - b = default.view(what,[]).get('F') + n0 = default.view(what,False) + n1 = default.view(what,[]) - assert a == b == {} + label = 'increments' if what == 'times' else what - @pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations + assert n0.get('F') is n1.get('F') is None and \ + len(n0.visible[label]) == len(n1.visible[label]) == 0 + + @pytest.mark.parametrize('what',['increments','times','phases','fields']) # ToDo: discuss homogenizations def test_view_more(self,default,what): empty = default.view(what,False) @@ -81,14 +84,17 @@ class TestResult: assert dict_equal(a,b) - @pytest.mark.parametrize('what',['increments','times','phases']) # ToDo: discuss homogenizations + @pytest.mark.parametrize('what',['increments','times','phases','fields']) # ToDo: discuss homogenizations def test_view_less(self,default,what): full = default.view(what,True) - a = full.view_less(what,'*').get('F') - b = full.view_less(what,True).get('F') + n0 = full.view_less(what,'*') + n1 = full.view_less(what,True) - assert a == b == {} + label = 'increments' if what == 'times' else what + + assert n0.get('F') is n1.get('F') is None and \ + len(n0.visible[label]) == len(n1.visible[label]) == 0 def test_view_invalid(self,default): with pytest.raises(AttributeError): @@ -189,7 +195,7 @@ class TestResult: default.add_stress_Cauchy('P','F') default.add_calculation('sigma_y','#sigma#',unit='y') default.add_equivalent_Mises('sigma_y') - assert default.get('sigma_y_vM') == {} + assert default.get('sigma_y_vM') is None def test_add_Mises_stress_strain(self,default): default.add_stress_Cauchy('P','F') @@ -380,8 +386,8 @@ class TestResult: pickle.dump(cur,f) with bz2.BZ2File((ref_path/'get'/fname).with_suffix('.pbz2')) as f: - assert dict_equal(cur,pickle.load(f)) - + ref = pickle.load(f) + assert cur is None if ref is None else dict_equal(cur,ref) @pytest.mark.parametrize('view,output,flatten,constituents,prune', [({},['F','P','F','L_p','F_e','F_p'],True,True,None), @@ -405,4 +411,5 @@ class TestResult: pickle.dump(cur,f) with bz2.BZ2File((ref_path/'place'/fname).with_suffix('.pbz2')) as f: - assert dict_equal(cur,pickle.load(f)) + ref = pickle.load(f) + assert cur is None if ref is None else dict_equal(cur,ref)