Ejemplo n.º 1
0
class Test_process(IrisTest):
    """A set of tests for the determine_schema method"""
    def setUp(self):
        """Set up the plugin and dataframe needed for this test"""
        self.cubes = CubeList([set_up_spot_cube(280)])
        self.data_directory = mkdtemp()
        self.plugin = SpotDatabase("csv", self.data_directory + "/test.csv",
                                   "improver", "time", "index")

    def tearDown(self):
        """Remove temporary directories created for testing."""
        Call(['rm', '-f', self.data_directory + '/test.csv'])
        Call(['rmdir', self.data_directory])

    @ManageWarnings(ignored_messages=IGNORED_MESSAGES,
                    warning_types=WARNING_TYPES)
    def test_save_as_csv(self):
        """Basic test using a basic dataframe as input"""
        self.plugin.process(self.cubes)
        with open(self.data_directory + '/test.csv') as f:
            resulting_string = f.read()
        expected_string = ',values\n1487311200,280.0\n'
        self.assertEqual(resulting_string, expected_string)

    @ManageWarnings(ignored_messages=IGNORED_MESSAGES,
                    warning_types=WARNING_TYPES)
    def test_unknown_output_type(self):
        """Test what happens if you give an unknown output type."""
        plugin = SpotDatabase("kitten", self.data_directory + "/test.csv",
                              "improver", "time", "index")
        message = ("Unrecognised output type. Current options are 'sqlite'"
                   " or 'csv', 'kitten' given.")
        with self.assertRaisesRegex(ValueError, message):
            plugin.process(self.cubes)
Ejemplo n.º 2
0
 def test_unknown_output_type(self):
     """Test what happens if you give an unknown output type."""
     plugin = SpotDatabase("kitten", self.data_directory + "/test.csv",
                           "improver", "time", "index")
     message = ("Unrecognised output type. Current options are 'sqlite'"
                " or 'csv', 'kitten' given.")
     with self.assertRaisesRegex(ValueError, message):
         plugin.process(self.cubes)