This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from kdmurray91/dev
WIP - tidy up code & increase test coverage
- Loading branch information
Showing
15 changed files
with
499 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import datetime as dt | ||
from unittest import TestCase, skip, skipIf, skipUnless | ||
from voluptuous import MultipleInvalid | ||
|
||
from tests import helpers | ||
from timestream.parse.validate import ( | ||
validate_timestream_manifest, | ||
v_date, | ||
v_datetime, | ||
v_num_str, | ||
) | ||
|
||
|
||
class TestValidateTimestreamManfiest(TestCase): | ||
|
||
"""Tests for ts.parse.validate.validate_timestream_manifest""" | ||
str_dict = { | ||
"name": "BVZ0022-GC05L-CN650D-Cam07~fullres-orig", | ||
"start_datetime": "2013_10_30_03_00_00", | ||
"end_datetime": "2013_10_30_06_00_00", | ||
"version": "1", | ||
"image_type": "jpg", | ||
"extension": "JPG", | ||
"interval": "30", | ||
"missing": [], | ||
} | ||
val_dict = { | ||
"name": "BVZ0022-GC05L-CN650D-Cam07~fullres-orig", | ||
"start_datetime": dt.datetime(2013, 10, 30, 3, 0, 0), | ||
"end_datetime": dt.datetime(2013, 10, 30, 6, 0, 0), | ||
"version": 1, | ||
"image_type": "jpg", | ||
"extension": "JPG", | ||
"interval": 30, | ||
"missing": [], | ||
} | ||
|
||
def test_validate_valid(self): | ||
"""Test validate_timestream_manifest with valid manfests""" | ||
self.assertDictEqual(validate_timestream_manifest(self.str_dict), | ||
self.val_dict) | ||
self.assertDictEqual(validate_timestream_manifest(self.val_dict), | ||
self.val_dict) | ||
|
||
def test_validate_invalid(self): | ||
"""Test validate_timestream_manifest with invalid manfests""" | ||
with self.assertRaises(TypeError): | ||
validate_timestream_manifest(None) | ||
with self.assertRaises(MultipleInvalid): | ||
validate_timestream_manifest({"A": "b", }) | ||
|
||
class TestDateValidators(TestCase): | ||
"""Tests for misc date format validators""" | ||
|
||
def test_v_date_invalid(self): | ||
"""Test v_date validator with invalid dates""" | ||
# standard date format | ||
date_str = "2013_44_01" | ||
with self.assertRaises(ValueError): | ||
v_date(date_str) | ||
# with different date format | ||
date_str = "2013-44-01" | ||
with self.assertRaises(ValueError): | ||
v_date(date_str) | ||
|
||
def test_v_date_valid(self): | ||
"""Test v_date validator with valid dates""" | ||
# standard date format | ||
date_str = "2013_03_01" | ||
self.assertEqual(v_date(date_str), dt.datetime(2013, 03, 01)) | ||
date_obj = dt.datetime(2013, 03, 01) | ||
self.assertEqual(v_date(date_obj), date_obj) | ||
# with different date format | ||
date_str = "2013-03-01" | ||
self.assertEqual(v_date(date_str, format="%Y-%m-%d"), | ||
dt.datetime(2013, 03, 01)) |
Oops, something went wrong.