def _py2_unicode_laundering(self): if six.PY2: unit_data_list = [u'1 Å', u'2 Å', u'3 Å'] cleaned_data_list = IOmodule._convert_unicode_to_str(unit_data_list) self.assertNotIn(u'2 Å', cleaned_data_list) self.assertIn('2 \xc3\x85', cleaned_data_list) unit_data_nested = [[u'1 Å', u'2 Å'], [u'3 Å', u'4 Å']] cleaned_data_nested = IOmodule._convert_unicode_to_str(unit_data_nested) self.assertNotIn(u'3 Å', cleaned_data_nested[1]) self.assertIn('3 \xc3\x85', cleaned_data_nested[1]) unit_data_dict = {u'1 Å': 1, u'2 Å': 2, 'tens': {u'10 Å': 10, u'20 Å': 20}} cleaned_data_dict = IOmodule._convert_unicode_to_str(unit_data_dict) self.assertNotIn(u'2 Å', cleaned_data_dict) self.assertNotIn(u'10 Å', cleaned_data_dict['tens']) self.assertIn('10 \xc3\x85', cleaned_data_dict['tens']) for item in ('x', 1, 2.34, (1, 2)): self.assertEqual(IOmodule._convert_unicode_to_str(item), item) self.assertIsInstance(IOmodule._convert_unicode_to_str(np.ones(5)), np.ndarray)
def runTest(self): self._save_stuff() self._save_wrong_attribute() self._save_wrong_dataset() self.loader = IOmodule(input_filename="Cars.foo", group_name="Volksvagen") self._wrong_filename() self._wrong_groupname() self._wrong_file() self._loading_attributes() self._loading_datasets() self._loading_structured_datasets()
def _wrong_file(self): poor_loader = IOmodule(input_filename="bumCars", group_name="nice_group") self.assertRaises(IOError, poor_loader.load, list_of_attributes="one_attribute")
def _save_wrong_dataset(self): poor_saver = IOmodule(input_filename="BadCars.foo", group_name="Volksvagen") poor_saver.add_data("BadPassengers", 4) self.assertRaises(ValueError, poor_saver.save)
def _save_wrong_attribute(self): poor_saver = IOmodule(input_filename="BadCars.foo", group_name="Volksvagen") poor_saver.add_attribute("BadPassengers", np.array([4])) self.assertRaises(ValueError, poor_saver.save)
def _save_stuff(self): saver = IOmodule(input_filename="Cars.foo", group_name="Volksvagen") # add some attributes saver.add_attribute("Fuel", 100) saver.add_attribute("Speed", 200) # add some datasets saver.add_data("Passengers", np.array([4])) saver.add_data("FireExtinguishers", np.array([2])) # add some mode complex data sets wheels = [{ "Winter": False, "Punctured": False, "Brand": "Mercedes", "Age": 2 }, { "Winter": False, "Punctured": False, "Brand": "Mercedes", "Age": 3 }, { "Winter": False, "Punctured": False, "Brand": "Mercedes", "Age": 5 }, { "Winter": False, "Punctured": True, "Brand": "Mercedes", "Age": 7 }] chairs = {"AdjustableHeadrests": True, "ExtraPadding": True} saver.add_data("wheels", wheels) saver.add_data("chairs", chairs) # save attributes and datasets saver.save()
def _save_stuff(self): saver = IOmodule(input_filename="Cars.foo", group_name="Volksvagen") # add some attributes saver.add_attribute("Fuel", 100) saver.add_attribute("Speed", 200) # add some datasets saver.add_data("Passengers", np.array([4])) saver.add_data("FireExtinguishers", np.array([2])) # add some mode complex data sets wheels = [{"Winter": False, "Punctured": False, "Brand": "Mercedes", "Age": 2}, {"Winter": False, "Punctured": False, "Brand": "Mercedes", "Age": 3}, {"Winter": False, "Punctured": False, "Brand": "Mercedes", "Age": 5}, {"Winter": False, "Punctured": True, "Brand": "Mercedes", "Age": 7}] chairs = {"AdjustableHeadrests": True, "ExtraPadding": True} saver.add_data("wheels", wheels) saver.add_data("chairs", chairs) # save attributes and datasets saver.save()