def test_pybool(self): for fstr_true in ('true', 'ture', 't', '.t'): self.assertEqual(pybool(fstr_true), True) for fstr_false in ('false', 'flase', 'f', '.f'): self.assertEqual(pybool(fstr_false), False) for fstr in ('g', '.', 'xyz'): self.assertRaises(ValueError, pybool, fstr)
def test_pybool(self): for fstr_true in ("true", "ture", "t", ".t"): self.assertEqual(pybool(fstr_true), True) for fstr_false in ("false", "flase", "f", ".f"): self.assertEqual(pybool(fstr_false), False) for fstr in ("g", ".", "xyz"): self.assertRaises(ValueError, pybool, fstr)
def parse_value(self, write_token=True, override=None): """Convert string repr of Fortran type to equivalent Python type.""" v_str = self.prior_token # Construct the complex string if v_str == '(': v_re = self.token self.update_tokens(write_token) assert self.token == ',' self.update_tokens(write_token) v_im = self.token self.update_tokens(write_token) assert self.token == ')' self.update_tokens(write_token, override) v_str = '({0}, {1})'.format(v_re, v_im) recast_funcs = [int, pyfloat, pycomplex, pybool, pystr] for f90type in recast_funcs: try: # Unclever hack.. integrate this better if f90type == pybool: value = pybool(v_str, self.strict_logical) else: value = f90type(v_str) return value except ValueError: continue
def test_pybool(self): for fstr_true in ('true', '.true.', 't', '.t.'): self.assertEqual(pybool(fstr_true), True) for fstr_false in ('false', '.false.', 'f', '.f.'): self.assertEqual(pybool(fstr_false), False) for fstr_true in ('ture', '.t'): self.assertEqual(pybool(fstr_true, strict_logical=False), True) for fstr_false in ('flase', '.f'): self.assertEqual(pybool(fstr_false, strict_logical=False), False) for fstr in ('ture', '.t', 'flase', '.f'): self.assertRaises(ValueError, pybool, fstr) for fstr in ('g', '.', 'xyz'): self.assertRaises(ValueError, pybool, fstr, strict_logical=False)