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_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_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_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_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_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_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_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_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_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_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_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)