def test_nonnumerc_version(self): idf_object = """ Version,A.Q; """ processor = IDFProcessor() with self.assertRaises(ProcessingException): processor.process_file_via_stream(StringIO.StringIO(idf_object))
def test_invalid_idf_object_required_field_no_default(self): idf_string = """ Version,12.9; MyObject,Name,ZoneName,1;""" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(self.idd_object) self.assertEqual(len(issues), 2)
def test_valid_defaulted_blank_idf_object(self): idf_string = """ Version,12.9; MyObject,Name,ZoneName,1,2,;""" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(self.idd_object) self.assertEqual(len(issues), 0)
def test_units_are_persisted_when_writing(self): idf_string = """ Version,12.9; MyObject,Name,ZoneName,1,2,3;""" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(self.idd_object) self.assertEqual(len(issues), 0) os = idf_object.object_string(self.idd_object) self.assertIn('{m}', os)
def test_units_are_persisted_when_writing(self): idf_string = """ Version,12.9; MyObject,Name,ZoneName,1,2,3;""" idf_structure = IDFProcessor().process_file_via_string(idf_string) issues = idf_structure.validate(self.idd_structure) self.assertEqual(len(issues), 0) import tempfile file_object = tempfile.NamedTemporaryFile() idf_structure.write_idf(file_object.name, self.idd_structure)
def test_missing_semicolon(self): idf_object = """ Version,1.1; Objecttype, object_name, something without a semicolon !- with a comment """ processor = IDFProcessor() with self.assertRaises(ProcessingException): processor.process_file_via_stream(StringIO.StringIO(idf_object))
def test_whole_idf_valid_with_comments(self): idf_string = """ Version,12.9; MyObject,1,1,1; ! ME COMMENT MyObject,1,1,1;""" idf_structure = IDFProcessor().process_file_via_string(idf_string) issues = idf_structure.validate(self.idd_structure) self.assertEqual(len(issues), 0) s_idf = idf_structure.whole_idf_string(self.idd_structure) self.assertTrue('ME COMMENT' in s_idf)
def test_rewriting_idf(self): idf_path = os.path.join(self.support_file_dir, "1ZoneEvapCooler.idf") idf_processor = IDFProcessor() idf_structure = idf_processor.process_file_given_file_path(idf_path) self.assertEquals(80, len(idf_structure.objects)) idd_path = os.path.join(self.support_file_dir, "Energy+.idd") idd_processor = IDDProcessor() idd_structure = idd_processor.process_file_given_file_path(idd_path) out_idf_file_path = tempfile.mktemp(suffix=".idf") # print("Writing new idf to: " + out_idf_file_path) idf_structure.write_idf(out_idf_file_path, idd_structure)
def test_valid_goofy_idf_2(self): idf_object = """ Version,81.9; ! here is a comment Objecttype, ! here is another comment! object_name, something, !- with a comment , last field with space; ! and comment for fun """ processor = IDFProcessor() idf_structure = processor.process_file_via_stream(StringIO.StringIO(idf_object)) self.assertEquals(3, len(idf_structure.objects)) # comment + two objects
def test_indented_idf(self): idf_object = """ Version,1.1; ObjectType, This Object Name, !- Name Descriptive Field, !- Field Name \t3.4, !- Numeric Field , !- Optional Blank Field Final Value; !- With Semicolon """ processor = IDFProcessor() idf_structure = processor.process_file_via_stream(StringIO.StringIO(idf_object)) self.assertEquals(2, len(idf_structure.objects))
def test_swapping_including_comment(self): idf_string = """ Version, 87.11; ObjectU, MyFirstKey; ! Comments here ObjectU, NotMyFirstKey; """ idf_structure = IDFProcessor().process_file_via_string(idf_string) idf_structure.global_swap({"MyFirstKey": "MySecondKey"}) idf_object = idf_structure.get_idf_objects_by_type("ObjectU")[0] self.assertIn("MySecondKey", idf_object.fields)
def test_valid_goofy_idf(self): idf_object = """ Version,1.1; Objecttype, ! comment object_name, something, !- with a comment , ! here is a comment line last field with space; ! and comment for fun """ processor = IDFProcessor() idf_structure = processor.process_file_via_stream(StringIO.StringIO(idf_object)) self.assertEquals(2, len(idf_structure.objects))
def test_single_line_validation(self): idd_string = """ !IDD_Version 56.1.0 !IDD_BUILD abcdef1011 \group MyGroup Version, A1; \\field VersionID Object;""" idd_object = IDDProcessor().process_file_via_string( idd_string).get_object_by_type('Object') idf_string = "Version,23.1;Object;" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('Object')[0] issues = idf_object.validate(idd_object) self.assertEqual(len(issues), 0)
def test_one_line_idf(self): idf_object = """Version,1.1;ObjectType,This Object Name,Descriptive Field,3.4,,Final Value;""" processor = IDFProcessor() idf_structure = processor.process_file_via_stream(StringIO.StringIO(idf_object)) self.assertEquals(2, len(idf_structure.objects))
def test_missing_required_field(self): idf_string = "Version,12.9;MyObject,,1,1;" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(self.idd_object) self.assertEqual(len(issues), 1)
def test_minimal_idf(self): idf_path = os.path.join(self.support_file_dir, "Minimal.idf") processor = IDFProcessor() idf_structure = processor.process_file_given_file_path(idf_path) self.assertEquals(1, len(idf_structure.objects)) self.assertAlmostEqual(idf_structure.version_float, 1.1, 1)
def test_blank_idf(self): idf_path = os.path.join(self.support_file_dir, "Blank.idf") processor = IDFProcessor() processor.process_file_given_file_path(idf_path)
def test_missing_idf(self): idf_path = os.path.join(self.support_file_dir, "NotReallyThere.idf") processor = IDFProcessor() with self.assertRaises(ProcessingException): processor.process_file_given_file_path(idf_path)
def test_valid_idf_file_complex(self): idf_path = os.path.join(self.support_file_dir, "RefBldgLargeHotelNew2004.idf") processor = IDFProcessor() idf_structure = processor.process_file_given_file_path(idf_path) self.assertEquals(1136, len(idf_structure.objects))
def test_valid_idf_file_simple(self): idf_path = os.path.join(self.support_file_dir, "1ZoneEvapCooler.idf") processor = IDFProcessor() idf_structure = processor.process_file_given_file_path(idf_path) self.assertEquals(80, len(idf_structure.objects))
def test_missing_version(self): # Missing version is now supported idf_string = "MyObject,1,1,1;" idf_processor = IDFProcessor().process_file_via_string(idf_string) version_object = idf_processor.get_idf_objects_by_type('Version') self.assertEqual(0, len(version_object))
def test_numeric_too_low_b(self): idf_string = "Version,12.9;MyObject,1,0,1;" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(self.idd_object) self.assertEqual(len(issues), 1)
def test_whole_idf_two_invalid(self): idf_string = "Version,12.9;MyObject,-1,1,1;MyObject,-1,1,1;" idf_structure = IDFProcessor().process_file_via_string(idf_string) issues = idf_structure.validate(self.idd_structure) self.assertEqual(len(issues), 2)
def test_multiple_unique_object(self): idf_string = "Version,12.9;ObjectU,1;ObjectU,1;" idf_structure = IDFProcessor().process_file_via_string(idf_string) issues = idf_structure.validate(self.idd_structure) self.assertEqual(len(issues), 1)
def test_missing_required_object(self): idf_string = "Version,12.9;OtherObject,1;" idf_structure = IDFProcessor().process_file_via_string(idf_string) issues = idf_structure.validate(self.idd_structure) self.assertEqual(len(issues), 1)
def test_valid_idf_object_but_None_idd_object(self): idf_string = "Version,12.9;MyObject,1,1,1;" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(None) self.assertEqual(len(issues), 0)
def test_non_numeric_autocalculate_but_not_allowed(self): idf_string = "Version,12.9;MyObject,AutoCalculate,1,1;" idf_object = IDFProcessor().process_file_via_string( idf_string).get_idf_objects_by_type('MyObject')[0] issues = idf_object.validate(self.idd_object) self.assertEqual(len(issues), 1)