from nose.tools import assert_true
from ..examples.sample_data import (temperature_ramp, multisource_event,
                                    image_and_scalar)
from metadatastore.api import Document

def run_example(example):
    events = example.run()
    assert_true(isinstance(events, list))
    assert_true(isinstance(events[0], Document))

def test_examples():
    for example in [temperature_ramp, multisource_event, image_and_scalar]:
        yield run_example, example

import unittest
from ..examples.sample_data import (temperature_ramp, multisource_event,
                                    image_and_scalar)
from metadatastore.api import Document

class CommonSampleDataTests(object):
    def setUp(self):
        pass

    def test_basic_usage(self):
        events = self.example.run()

        # check expected types
        self.assertTrue(isinstance(events, list))
        self.assertTrue(isinstance(events[0], Document))


class TestTemperatureRamp(CommonSampleDataTests, unittest.TestCase):

    def setUp(self):
        self.example = temperature_ramp


class TestMultisourceEvent(CommonSampleDataTests, unittest.TestCase):

    def setUp(self):
        self.example = multisource_event


class TestImageAndScalar(CommonSampleDataTests, unittest.TestCase):

    def setUp(self):
        self.example = image_and_scalar

--- 
+++ 
@@ -1,33 +1,13 @@
-import unittest
+from nose.tools import assert_true
 from ..examples.sample_data import (temperature_ramp, multisource_event,
                                     image_and_scalar)
 from metadatastore.api import Document
 
-class CommonSampleDataTests(object):
-    def setUp(self):
-        pass
+def run_example(example):
+    events = example.run()
+    assert_true(isinstance(events, list))
+    assert_true(isinstance(events[0], Document))
 
-    def test_basic_usage(self):
-        events = self.example.run()
-
-        # check expected types
-        self.assertTrue(isinstance(events, list))
-        self.assertTrue(isinstance(events[0], Document))
-
-
-class TestTemperatureRamp(CommonSampleDataTests, unittest.TestCase):
-
-    def setUp(self):
-        self.example = temperature_ramp
-
-
-class TestMultisourceEvent(CommonSampleDataTests, unittest.TestCase):
-
-    def setUp(self):
-        self.example = multisource_event
-
-
-class TestImageAndScalar(CommonSampleDataTests, unittest.TestCase):
-
-    def setUp(self):
-        self.example = image_and_scalar
+def test_examples():
+    for example in [temperature_ramp, multisource_event, image_and_scalar]:
+        yield run_example, example
REF: Use generator test for examples.
