Skip to content

Commit

Permalink
lava_results_app: add test case for YAML Decimal object conversion
Browse files Browse the repository at this point in the history
The test case metadata may contain measurements which are stored as
Decimal objects in the database.  By default, they get dumped in YAML
as a Decimal Python object which makes it incompatible with standard
parsers when the results are exported (in YAML or CSV).

Add a test case to catch this problem with arbitrary metadata,
checking the actual YAML text stored in the TestCase object.

Signed-off-by: Guillaume Tucker <[email protected]>
  • Loading branch information
gctucker authored and Neil Williams committed Oct 30, 2018
1 parent 1744ea7 commit 26bf0af
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lava_results_app/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ def test_duration(self):
action_data.save(update_fields=['timeout'])
self.assertEqual(action_data.timeout, 300)

def test_decimal_yaml_dump(self):
job = TestJob.from_yaml_and_user(
self.factory.make_job_yaml(), self.user)
test_dict = {
'definition': 'unit-test',
'case': 'unit-test',
'measurement': decimal.Decimal(1234.5),
'result': 'pass',
}
test_case = map_scanned_results(test_dict, job, {}, None)
metadata_yaml_ref = "{case: unit-test, definition: unit-test, measurement: '1234.5', result: pass}"
self.assertEqual(metadata_yaml_ref, test_case.metadata.strip())

def test_case_as_url(self):
job = TestJob.from_yaml_and_user(
self.factory.make_job_yaml(), self.user)
Expand Down

0 comments on commit 26bf0af

Please sign in to comment.