Exemple #1
0
 def test_register_section(self):
     golf = cube.DataCube(golf_path)
     golf.stratigraphy_from('eta', dz=0.1)
     golf.register_section('testsection',
                           section.StrikeSection(distance_idx=10))
     assert golf.sections is golf.section_set
     assert len(golf.sections.keys()) == 1
     assert 'testsection' in golf.sections.keys()
     with pytest.raises(TypeError, match=r'`SectionInstance` .*'):
         golf.register_section('fail1', 'astring')
     with pytest.raises(TypeError, match=r'`SectionInstance` .*'):
         golf.register_section('fail2', 22)
     with pytest.raises(TypeError, match=r'`name` .*'):
         golf.register_section(22, section.StrikeSection(distance_idx=10))
Exemple #2
0
 def test_show_section_mocked_BaseSection_show(self):
     golf = cube.DataCube(golf_path)
     golf.register_section('displaysection',
                           section.StrikeSection(distance_idx=10))
     golf.sections['displaysection'].show = mock.MagicMock()
     mocked = golf.sections['displaysection'].show
     # no arguments is an error
     with pytest.raises(TypeError, match=r'.* missing 2 .*'):
         golf.show_section()
     # one argument is an error
     with pytest.raises(TypeError, match=r'.* missing 1 .*'):
         golf.show_section('displaysection')
     # three arguments is an error
     with pytest.raises(TypeError, match=r'.* takes 3 .*'):
         golf.show_section('one', 'two', 'three')
     # two arguments passes to BaseSection.show()
     golf.show_section('displaysection', 'eta')
     assert mocked.call_count == 1
     # kwargs should be passed along to BaseSection.show
     golf.show_section('displaysection', 'eta', ax=100)
     assert mocked.call_count == 2
     mocked.assert_called_with('eta', ax=100)
     # first arg must be a string
     with pytest.raises(TypeError, match=r'`name` was not .*'):
         golf.show_section(1, 'two')
Exemple #3
0
 def test_nostratigraphy_default_attribute_derived_variable(self):
     golf = cube.DataCube(golf_path)
     golf.register_section('testsection',
                           section.StrikeSection(distance_idx=10))
     assert golf._knows_stratigraphy is False
     with pytest.raises(utils.NoStratigraphyError):
         golf.sections['testsection']['velocity'].strat.as_stratigraphy()
Exemple #4
0
 def test_section_no_stratigraphy(self):
     sc = section.StrikeSection(self.fixeddatacube, distance_idx=10)
     _ = sc['velocity'][:, 1]
     assert not hasattr(sc, 'strat_attr')
     with pytest.raises(utils.NoStratigraphyError):
         _ = sc.strat_attr
     with pytest.raises(utils.NoStratigraphyError):
         _ = sc['velocity'].strat.as_preserved()
Exemple #5
0
 def test_sections_slice_op(self):
     golf = cube.DataCube(golf_path)
     golf.stratigraphy_from('eta', dz=0.1)
     golf.register_section('testsection',
                           section.StrikeSection(distance_idx=10))
     assert 'testsection' in golf.sections.keys()
     slc = golf.sections['testsection']
     assert issubclass(type(slc), section.BaseSection)
Exemple #6
0
 def test_section_with_stratigraphy(self):
     assert hasattr(self.fixeddatacube, 'strat_attr')
     sc = section.StrikeSection(self.fixeddatacube, distance_idx=10)
     assert sc.strat_attr is self.fixeddatacube.strat_attr
     _take = sc['velocity'][:, 1]
     assert _take.shape == (self.fixeddatacube.shape[0], )
     assert hasattr(sc, 'strat_attr')
     _take2 = sc['velocity'].strat.as_preserved()
     assert _take2.shape == (self.fixeddatacube.shape[0],
                             self.fixeddatacube.shape[2])