Skip to content

Commit

Permalink
tests: Assert on NAN
Browse files Browse the repository at this point in the history
gabbi allows to write custom value checker since 1.37.0.

This change uses that to check that .NAN is NAN.
  • Loading branch information
Mehdi Abaakouk authored and pastamaker[bot] committed Nov 9, 2017
1 parent dfdb68f commit 02b6787
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
13 changes: 13 additions & 0 deletions gnocchi/tests/functional/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@

import daiquiri
from gabbi import fixture
import numpy
from oslo_config import cfg
from oslo_middleware import cors
import sqlalchemy_utils
import yaml

from gnocchi.cli import metricd
from gnocchi import incoming
Expand All @@ -50,6 +52,17 @@ def setup_app():
return app.load_app(**LOAD_APP_KWARGS)


class AssertNAN(yaml.YAMLObject):
def __eq__(self, other):
try:
return numpy.isnan(other)
except TypeError:
return False


yaml.add_constructor(u'!AssertNAN', lambda loader, node: AssertNAN())


class ConfigFixture(fixture.GabbiFixture):
"""Establish the relevant configuration fixture, per test file.
Expand Down
33 changes: 16 additions & 17 deletions gnocchi/tests/functional/gabbits/aggregates-with-metric-ids.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ tests:

- name: no overlap null
POST: /v1/aggregates?fill=null
xfail: gabbi use assertEqual to compare .NAN which is always false
data:
operations: "(metric ($HISTORY['create metric1'].$RESPONSE['$.id'] mean) ($HISTORY['create metric4'].$RESPONSE['$.id'] mean))"
response_json_paths:
Expand All @@ -440,32 +439,32 @@ tests:
- ["2015-03-06T14:35:00+00:00", 60.0, 10.0]
- ['2015-03-06T14:37:00+00:00', 60.0, 15.0]
- ['2015-03-06T14:38:00+00:00', 60.0, 15.0]
- ["2017-04-06T14:33:00+00:00", 60.0, .NAN]
- ["2017-04-06T14:34:00+00:00", 60.0, .NAN]
- ["2017-04-06T14:33:00+00:00", 60.0, !AssertNAN ]
- ["2017-04-06T14:34:00+00:00", 60.0, !AssertNAN ]
- ["2015-03-06T14:33:57+00:00", 1.0, 43.1]
- ["2015-03-06T14:34:12+00:00", 1.0, 12.0]
- ["2015-03-06T14:34:15+00:00", 1.0, -16.0]
- ["2015-03-06T14:35:12+00:00", 1.0, 9.0]
- ["2015-03-06T14:35:15+00:00", 1.0, 11.0]
- ['2015-03-06T14:37:00+00:00', 1.0, 15.0]
- ['2015-03-06T14:38:00+00:00', 1.0, 15.0]
- ["2017-04-06T14:33:57+00:00", 1.0, .NAN]
- ["2017-04-06T14:34:12+00:00", 1.0, .NAN]
- ["2017-04-06T14:33:57+00:00", 1.0, !AssertNAN ]
- ["2017-04-06T14:34:12+00:00", 1.0, !AssertNAN ]
$."$HISTORY['create metric4'].$RESPONSE['$.id']_mean":
- ["2015-03-06T14:33:00+00:00", 60.0, .NAN]
- ["2015-03-06T14:34:00+00:00", 60.0, .NAN]
- ["2015-03-06T14:35:00+00:00", 60.0, .NAN]
- ['2015-03-06T14:37:00+00:00', 60.0, .NAN]
- ['2015-03-06T14:38:00+00:00', 60.0, .NAN]
- ["2015-03-06T14:33:00+00:00", 60.0, !AssertNAN ]
- ["2015-03-06T14:34:00+00:00", 60.0, !AssertNAN ]
- ["2015-03-06T14:35:00+00:00", 60.0, !AssertNAN ]
- ['2015-03-06T14:37:00+00:00', 60.0, !AssertNAN ]
- ['2015-03-06T14:38:00+00:00', 60.0, !AssertNAN ]
- ["2017-04-06T14:33:00+00:00", 60.0, 20.0]
- ["2017-04-06T14:34:00+00:00", 60.0, 10.0]
- ["2015-03-06T14:33:57+00:00", 1.0, .NAN]
- ["2015-03-06T14:34:12+00:00", 1.0, .NAN]
- ["2015-03-06T14:34:15+00:00", 1.0, .NAN]
- ["2015-03-06T14:35:12+00:00", 1.0, .NAN]
- ["2015-03-06T14:35:15+00:00", 1.0, .NAN]
- ['2015-03-06T14:37:00+00:00', 1.0, .NAN]
- ['2015-03-06T14:38:00+00:00', 1.0, .NAN]
- ["2015-03-06T14:33:57+00:00", 1.0, !AssertNAN ]
- ["2015-03-06T14:34:12+00:00", 1.0, !AssertNAN ]
- ["2015-03-06T14:34:15+00:00", 1.0, !AssertNAN ]
- ["2015-03-06T14:35:12+00:00", 1.0, !AssertNAN ]
- ["2015-03-06T14:35:15+00:00", 1.0, !AssertNAN ]
- ['2015-03-06T14:37:00+00:00', 1.0, !AssertNAN ]
- ['2015-03-06T14:38:00+00:00', 1.0, !AssertNAN ]
- ["2017-04-06T14:33:57+00:00", 1.0, 20.0]
- ["2017-04-06T14:34:12+00:00", 1.0, 10.0]

Expand Down
3 changes: 2 additions & 1 deletion gnocchi/tests/functional/test_gabbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ def load_tests(loader, tests, pattern):
test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
return driver.build_tests(test_dir, loader, host=None, prefix=PREFIX,
intercept=fixtures.setup_app,
fixture_module=fixtures)
fixture_module=fixtures,
safe_yaml=False)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ doc =
reno>=1.6.2
test =
pifpaf[ceph,gnocchi]>=1.0.1
gabbi>=1.30.0
gabbi>=1.37.0
coverage>=3.6
fixtures
mock
Expand Down

0 comments on commit 02b6787

Please sign in to comment.