deltametrics/section.py
changed.
Other files ignored by Codecov
tests/test_section.py
has changed.
1 | 1 | import abc |
|
2 | + | import warnings |
|
2 | 3 | ||
3 | 4 | import numpy as np |
|
4 | 5 | from scipy import stats, sparse |
203 | 204 | self._trace = None |
|
204 | 205 | self._shape = None |
|
205 | 206 | self._variables = None |
|
206 | - | self._name = name |
|
207 | 207 | self.cube = None |
|
208 | 208 | ||
209 | 209 | self.section_type = section_type |
|
210 | + | self._name = name |
|
210 | 211 | ||
211 | 212 | if len(args) > 1: |
|
212 | 213 | raise ValueError('Expected single positional argument to \ |
228 | 229 | _gottype=type(CubeInstance))) |
|
229 | 230 | self.cube = CubeInstance |
|
230 | 231 | self._variables = self.cube.variables |
|
231 | - | self._name = self._name or name or self.section_type |
|
232 | + | # self._name = self._name or name or self.section_type |
|
233 | + | self.name = name # use the setter to determine the _name |
|
232 | 234 | self._compute_section_coords() |
|
233 | 235 | self._compute_section_attrs() |
|
234 | 236 |
236 | 238 | def name(self): |
|
237 | 239 | return self._name |
|
238 | 240 | ||
241 | + | @name.setter |
|
242 | + | def name(self, var): |
|
243 | + | if (self._name is None): |
|
244 | + | # _name is not yet set |
|
245 | + | self._name = var or self.section_type |
|
246 | + | else: |
|
247 | + | # _name is already set |
|
248 | + | if not (var is None): |
|
249 | + | warnings.warn(UserWarning("`name` argument supplied to \ |
|
250 | + | instantiated `Section` object. To change the name of \ |
|
251 | + | a Section, you must set the attribute directly with \ |
|
252 | + | `section._name = 'name'`.")) |
|
253 | + | # do nothing |
|
254 | + | ||
239 | 255 | @abc.abstractmethod |
|
240 | 256 | def _compute_section_coords(self): |
|
241 | 257 | """Should calculate x-y coordinates of the section. |
Files | Coverage |
---|---|
deltametrics | 91.02% |
Project Totals (8 files) | 91.02% |
PYTHON=3.6 OS=ubuntu-latest
PYTHON=3.8 OS=ubuntu-latest
PYTHON=3.7 OS=macos-latest
PYTHON=3.7 OS=ubuntu-latest
PYTHON=3.7 OS=windows-latest
PYTHON=3.6 OS=windows-latest
PYTHON=3.8 OS=macos-latest
PYTHON=3.8 OS=windows-latest
PYTHON=3.6 OS=macos-latest