def test_pyReader_Factory(self): # print '\tchecking that FileReaderFactory returns default readASDF class' reader = FileReaderFactory( 'test/Valid_Kameleon_File.asdf').createPyReader() # self.assertEqual(type(reader),readASDF.__class__) #this doesn't work self.assertIs(issubclass(reader.__class__, pyKameleon.FileReader), True) # as long as this works, we should be good
def test_missing_attributes(self): filename = self.file_prefix + 'attributeError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test( filename, explode_variables=explode_variables, variables=variables, global_attributes=global_attributes, #missing 'model_name' fields=fields) if self.verbose: print '\tchecking that file ' + filename + ' is invalid (missing certain attributes)' self.testReader = FileReaderFactory(filename).createPyReader() self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.check_global_attributes() with self.assertRaises(NameError): self.testReader.check_variable_attributes()
def test_missing_attributes(self): filename = self.file_prefix + 'attributeError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test(filename, explode_variables = explode_variables, variables = variables, global_attributes = global_attributes, #missing 'model_name' fields = fields ) if self.verbose: print '\tchecking that file ' + filename + ' is invalid (missing certain attributes)' self.testReader = FileReaderFactory(filename).createPyReader() self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.check_global_attributes() with self.assertRaises(NameError): self.testReader.check_variable_attributes()
class Test_fail_invalid_file(unittest.TestCase): def setUp(self): self.testReader = readASDF() self.file_prefix = 'test/Invalid_Kameleon_File_' self.verbose = False if self.verbose: print 'Test invalid file:' # self.testReader.debug = True def tearDown(self): self.testReader.close() if self.verbose: print ' ... success!\n' def test_missing_attributes(self): filename = self.file_prefix + 'attributeError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test(filename, explode_variables = explode_variables, variables = variables, global_attributes = global_attributes, #missing 'model_name' fields = fields ) if self.verbose: print '\tchecking that file ' + filename + ' is invalid (missing certain attributes)' self.testReader = FileReaderFactory(filename).createPyReader() self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.check_global_attributes() with self.assertRaises(NameError): self.testReader.check_variable_attributes() def test_missing_variables(self): filename = self.file_prefix + 'variables_NameError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test(filename, explode_variables = explode_variables, variables_NameError = variables, global_attributes = global_attributes, fields = fields) if self.verbose: print '\tchecking that file ' + filename + " is missing 'variables'" self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.setVariables() def test_missing_global_attributes(self): filename = self.file_prefix + 'globals_NameError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test(filename, explode_variables = explode_variables, variables = variables, global_attributes_NameError = global_attributes, fields = fields) if self.verbose: print '\tchecking that file ' + filename + " is missing 'global_attributes'" self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.setGlobalAttributes()
class Test_fail_invalid_file(unittest.TestCase): def setUp(self): self.testReader = readASDF() self.file_prefix = 'test/Invalid_Kameleon_File_' self.verbose = False if self.verbose: print 'Test invalid file:' # self.testReader.debug = True def tearDown(self): self.testReader.close() if self.verbose: print ' ... success!\n' def test_missing_attributes(self): filename = self.file_prefix + 'attributeError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test( filename, explode_variables=explode_variables, variables=variables, global_attributes=global_attributes, #missing 'model_name' fields=fields) if self.verbose: print '\tchecking that file ' + filename + ' is invalid (missing certain attributes)' self.testReader = FileReaderFactory(filename).createPyReader() self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.check_global_attributes() with self.assertRaises(NameError): self.testReader.check_variable_attributes() def test_missing_variables(self): filename = self.file_prefix + 'variables_NameError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test(filename, explode_variables=explode_variables, variables_NameError=variables, global_attributes=global_attributes, fields=fields) if self.verbose: print '\tchecking that file ' + filename + " is missing 'variables'" self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.setVariables() def test_missing_global_attributes(self): filename = self.file_prefix + 'globals_NameError.asdf' variables, global_attributes, fields = get_fail_data() explode_variables = [variables[var]['data'] for var in variables] write_asdf_test(filename, explode_variables=explode_variables, variables=variables, global_attributes_NameError=global_attributes, fields=fields) if self.verbose: print '\tchecking that file ' + filename + " is missing 'global_attributes'" self.assertEqual(self.testReader.openFile(filename), pyKameleon.FileReader.NOT_A_VALID_KAMELEON_FILE) with self.assertRaises(NameError): self.testReader.setGlobalAttributes()