mirror of
https://github.com/adrienverge/yamllint.git
synced 2024-11-21 23:27:22 -06:00
float-values: Refactor tests to be less verbose
The goal is to be more concise thus more readable, as well as consistent with most other tests.
This commit is contained in:
parent
e6af957131
commit
dc2d0991e0
@ -20,36 +20,14 @@ class FloatValuesTestCase(RuleTestCase):
|
||||
rule_id = 'float-values'
|
||||
|
||||
def test_disabled(self):
|
||||
conf = (
|
||||
'float-values: disable\n'
|
||||
'new-line-at-end-of-file: disable\n'
|
||||
'document-start: disable\n'
|
||||
)
|
||||
self.check('angle: 0.0', conf)
|
||||
self.check('angle: .NaN', conf)
|
||||
self.check('angle: .INF', conf)
|
||||
self.check('angle: .1', conf)
|
||||
self.check('angle: 10e-6', conf)
|
||||
self.check(
|
||||
'- &angle .0\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
)
|
||||
self.check(
|
||||
'- &angle 10e6\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
)
|
||||
self.check(
|
||||
'- &angle .nan\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
)
|
||||
self.check(
|
||||
'- &angle .inf\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
)
|
||||
conf = 'float-values: disable\n'
|
||||
self.check('---\n'
|
||||
'- 0.0\n'
|
||||
'- .NaN\n'
|
||||
'- .INF\n'
|
||||
'- .1\n'
|
||||
'- 10e-6\n',
|
||||
conf)
|
||||
|
||||
def test_numeral_before_decimal(self):
|
||||
conf = (
|
||||
@ -57,25 +35,19 @@ class FloatValuesTestCase(RuleTestCase):
|
||||
' require-numeral-before-decimal: true\n'
|
||||
' forbid-scientific-notation: false\n'
|
||||
' forbid-nan: false\n'
|
||||
' forbid-inf: false\n'
|
||||
'new-line-at-end-of-file: disable\n'
|
||||
'document-start: disable\n'
|
||||
)
|
||||
self.check('angle: .1', conf, problem=(1, 8))
|
||||
self.check('angle: 0.0', conf)
|
||||
self.check('angle: \'.1\'', conf)
|
||||
self.check('angle: !custom_tag 0.0', conf)
|
||||
self.check(
|
||||
'- &angle 0.0\n'
|
||||
'- *angle\n',
|
||||
conf
|
||||
)
|
||||
self.check(
|
||||
'- &angle .0\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem=(1, 10)
|
||||
)
|
||||
' forbid-inf: false\n')
|
||||
self.check('---\n'
|
||||
'- 0.0\n'
|
||||
'- .1\n'
|
||||
'- \'.1\'\n'
|
||||
'- !custom_tag .2\n'
|
||||
'- &angle1 0.0\n'
|
||||
'- *angle1\n'
|
||||
'- &angle2 .3\n'
|
||||
'- *angle2\n',
|
||||
conf,
|
||||
problem1=(3, 3),
|
||||
problem2=(8, 11))
|
||||
|
||||
def test_scientific_notation(self):
|
||||
conf = (
|
||||
@ -83,32 +55,24 @@ class FloatValuesTestCase(RuleTestCase):
|
||||
' require-numeral-before-decimal: false\n'
|
||||
' forbid-scientific-notation: true\n'
|
||||
' forbid-nan: false\n'
|
||||
' forbid-inf: false\n'
|
||||
'new-line-at-end-of-file: disable\n'
|
||||
'document-start: disable\n'
|
||||
)
|
||||
self.check('angle: 10e6', conf, problem=(1, 8))
|
||||
self.check('angle: 10e-6', conf, problem=(1, 8))
|
||||
self.check('angle: 0.00001', conf)
|
||||
self.check('angle: \'10e-6\'', conf)
|
||||
self.check('angle: !custom_tag 10e-6', conf)
|
||||
self.check(
|
||||
'- &angle 0.000001\n'
|
||||
'- *angle\n',
|
||||
conf
|
||||
)
|
||||
self.check(
|
||||
'- &angle 10e-6\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem=(1, 10)
|
||||
)
|
||||
self.check(
|
||||
'- &angle 10e6\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem=(1, 10)
|
||||
)
|
||||
' forbid-inf: false\n')
|
||||
self.check('---\n'
|
||||
'- 10e6\n'
|
||||
'- 10e-6\n'
|
||||
'- 0.00001\n'
|
||||
'- \'10e-6\'\n'
|
||||
'- !custom_tag 10e-6\n'
|
||||
'- &angle1 0.000001\n'
|
||||
'- *angle1\n'
|
||||
'- &angle2 10e-6\n'
|
||||
'- *angle2\n'
|
||||
'- &angle3 10e6\n'
|
||||
'- *angle3\n',
|
||||
conf,
|
||||
problem1=(2, 3),
|
||||
problem2=(3, 3),
|
||||
problem3=(9, 11),
|
||||
problem4=(11, 11))
|
||||
|
||||
def test_nan(self):
|
||||
conf = (
|
||||
@ -116,20 +80,18 @@ class FloatValuesTestCase(RuleTestCase):
|
||||
' require-numeral-before-decimal: false\n'
|
||||
' forbid-scientific-notation: false\n'
|
||||
' forbid-nan: true\n'
|
||||
' forbid-inf: false\n'
|
||||
'new-line-at-end-of-file: disable\n'
|
||||
'document-start: disable\n'
|
||||
)
|
||||
self.check('angle: .NaN', conf, problem=(1, 8))
|
||||
self.check('angle: .NAN', conf, problem=(1, 8))
|
||||
self.check('angle: \'.NaN\'', conf)
|
||||
self.check('angle: !custom_tag .NaN', conf)
|
||||
self.check(
|
||||
'- &angle .nan\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem=(1, 10)
|
||||
)
|
||||
' forbid-inf: false\n')
|
||||
self.check('---\n'
|
||||
'- .NaN\n'
|
||||
'- .NAN\n'
|
||||
'- \'.NaN\'\n'
|
||||
'- !custom_tag .NaN\n'
|
||||
'- &angle .nan\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem1=(2, 3),
|
||||
problem2=(3, 3),
|
||||
problem3=(6, 10))
|
||||
|
||||
def test_inf(self):
|
||||
conf = (
|
||||
@ -137,25 +99,22 @@ class FloatValuesTestCase(RuleTestCase):
|
||||
' require-numeral-before-decimal: false\n'
|
||||
' forbid-scientific-notation: false\n'
|
||||
' forbid-nan: false\n'
|
||||
' forbid-inf: true\n'
|
||||
'new-line-at-end-of-file: disable\n'
|
||||
'document-start: disable\n'
|
||||
)
|
||||
self.check('angle: .inf', conf, problem=(1, 8))
|
||||
self.check('angle: .INF', conf, problem=(1, 8))
|
||||
self.check('angle: -.inf', conf, problem=(1, 8))
|
||||
self.check('angle: -.INF', conf, problem=(1, 8))
|
||||
self.check('angle: \'.inf\'', conf)
|
||||
self.check('angle: !custom_tag .inf', conf)
|
||||
self.check(
|
||||
'- &angle .inf\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem=(1, 10)
|
||||
)
|
||||
self.check(
|
||||
'- &angle -.inf\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem=(1, 10)
|
||||
)
|
||||
' forbid-inf: true\n')
|
||||
self.check('---\n'
|
||||
'- .inf\n'
|
||||
'- .INF\n'
|
||||
'- -.inf\n'
|
||||
'- -.INF\n'
|
||||
'- \'.inf\'\n'
|
||||
'- !custom_tag .inf\n'
|
||||
'- &angle .inf\n'
|
||||
'- *angle\n'
|
||||
'- &angle -.inf\n'
|
||||
'- *angle\n',
|
||||
conf,
|
||||
problem1=(2, 3),
|
||||
problem2=(3, 3),
|
||||
problem3=(4, 3),
|
||||
problem4=(5, 3),
|
||||
problem5=(8, 10),
|
||||
problem6=(10, 10))
|
||||
|
Loading…
Reference in New Issue
Block a user