Пример #1
0
    def setUp(self):
        idd_string = """
    !IDD_Version 13.9.0
    !IDD_BUILD abcdef1018
    \group MyGroup
    Version,
      A1;  \\field VersionID

    MyObject,
           \\min-fields 5
      A1,  \\field Name
           \\required-field
      A2,  \\field Zone Name
           \\required-field
      N1,  \\field A
           \\required-field
           \\units m
      N2,  \\field B
           \\required-field
      N3;  \\field C
           \\default 0.8
           \\required-field
            """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
        self.idd_object = self.idd_structure.get_object_by_type('MyObject')
Пример #2
0
 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)
Пример #3
0
    def test_invalid_idd_obj_lookup(self):
        idd_object = """
!IDD_Version 1.2.0
!IDD_BUILD abcdef0100
\\group Stuff
Version,A1;
"""
        processor = IDDProcessor()
        ret_value = processor.process_file_via_stream(
            StringIO.StringIO(idd_object))
        bad_obj = ret_value.get_object_by_type("noObjecT")
        self.assertIsNone(bad_obj)
Пример #4
0
    def test_single_line_obj_lookup(self):
        idd_object = """
!IDD_Version 1.2.0
!IDD_BUILD abcdef0011
Simulation Input;
\\group Stuff
Version,A1;
"""
        processor = IDDProcessor()
        ret_value = processor.process_file_via_stream(
            StringIO.StringIO(idd_object))
        bad_obj = ret_value.get_object_by_type("simulation input")
        self.assertTrue(bad_obj)
Пример #5
0
    def test_proper_idd_indented(self):
        idd_object = """
    !IDD_Version 1.2.0
    !IDD_BUILD abcdef0001
    \\group Simulation Parameters

    Version,
          \\memo Specifies the EnergyPlus version of the IDF file.
          \\unique-object
          \format singleLine
      A1 ; \\field Version Identifier
          \\default 8.6
    """
        processor = IDDProcessor()
        ret_value = processor.process_file_via_stream(
            StringIO.StringIO(idd_object))
        self.assertEquals(1, len(ret_value.groups))
        self.assertEquals(1, len(ret_value.groups[0].objects))
Пример #6
0
 def test_missing_build(self):
     idd_string = """
     !IDD_Version 1.2.0
     \group MyGroup
     MyObject,
       N1;  \\field NumericFieldA
     """
     with self.assertRaises(ProcessingException):
         IDDProcessor().process_file_via_string(idd_string)
Пример #7
0
 def test_missing_version(self):
     idd_string = """
     !IDD_BUILD abcdef0111
     \group MyGroup
     MyObject,
       N1;  \\field NumericFieldA
     """
     with self.assertRaises(ProcessingException):
         IDDProcessor().process_file_via_string(idd_string)
Пример #8
0
    def test_new_reference_class_name(self):
        idd_object = """
!IDD_Version 0.1.4
!IDD_BUILD abcded0810
\\group Simulation Parameters
NewObject,
  A1;  \\field Name
       \\required-field
       \\type alpha
       \\reference-class-name validBranchEquipmentTypes
       \\reference validBranchEquipmentNames
        """
        processor = IDDProcessor()
        ret_value = processor.process_file_via_stream(
            StringIO.StringIO(idd_object))
        self.assertEquals(1, len(ret_value.groups))
        self.assertEquals(1, len(ret_value.groups[0].objects))
        version_obj = ret_value.get_object_by_type("NewObject")
        self.assertEquals(1, len(version_obj.fields))
Пример #9
0
 def test_bad_non_numeric_metadata(self):
     idd_string = """
     !IDD_Version 122.6.0
     !IDD_BUILD abcdef1000
     \group MyGroup
     MyObject,
       \\min-fields Q
       N1;  \\field NumericFieldA
     """
     with self.assertRaises(ProcessingException):
         IDDProcessor().process_file_via_string(idd_string)
Пример #10
0
    def setUp(self):
        idd_string = """
    !IDD_Version 87.11.0
    !IDD_BUILD abcdef1011
    \group MyGroup
    Version,
      A1;  \\field VersionID

    ObjectU,
      A1;  \\field My field name
            """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
Пример #11
0
    def test_repeated_object_meta_idd(self):
        idd_object = """
!IDD_Version 0.1.0
!IDD_BUILD abcdef0010
\\group Simulation Parameters

Version,
      \\memo Specifies the EnergyPlus version of the IDF file.
      \\memo Some additional memo line
      \\unique-object
      \\format singleLine
  A1 ; \\field Version Identifier
      \\default 8.6

"""
        processor = IDDProcessor()
        ret_value = processor.process_file_via_stream(
            StringIO.StringIO(idd_object))
        self.assertEquals(1, len(ret_value.groups))
        self.assertEquals(1, len(ret_value.groups[0].objects))
        version_obj = ret_value.get_object_by_type("version")
        self.assertEquals(1, len(version_obj.fields))
Пример #12
0
 def test_invalid_idd_metadata(self):
     idd_string = """
     !IDD_Version 1.2.0
     !IDD_BUILD abcdef0110
     \group MyGroup
     MyObject,
       N1,  \\field NumericFieldA
       N2;  \\field NumericFieldB
            \\autosizQble
             """
     with self.assertRaises(ProcessingException):
         IDDProcessor().process_file_via_string(
             idd_string).get_object_by_type('MyObject')
Пример #13
0
 def test_valid_single_token_object_with_idd(self):
     idd_string = """
     !IDD_Version 1.2.0
     !IDD_BUILD abcdef1001
     \group MyGroup
     SingleLineObject;"""
     idd_object = IDDProcessor().process_file_via_string(
         idd_string).get_object_by_type('SingleLineObject')
     tokens = ["SingleLineObject"]
     obj = IDFObject(tokens)
     self.assertEquals("SingleLineObject", obj.object_name)
     self.assertEquals(0, len(obj.fields))
     s = obj.object_string(idd_object)
     self.assertEquals("SingleLineObject;\n", s)
Пример #14
0
    def setUp(self):
        idd_string = """
!IDD_Version 12.9.0
!IDD_BUILD abcdef1010
\group MyGroup
Version,
  A1;  \\field VersionID

MyObject,
  N1,  \\field NumericFieldA
       \\minimum 0
       \\maximum 2
       \\required-field
  N2,  \\field NumericFieldB
       \\minimum> 0
       \\maximum< 2
       \\autosizable
  N3;  \\field NumericFieldB
       \\minimum> 0
       \\maximum< 2
       \\autocalculatable
        """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
        self.idd_object = self.idd_structure.get_object_by_type('MyObject')
Пример #15
0
    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)
Пример #16
0
    def setUp(self):
        idd_string = """
!IDD_Version 8.1.0
!IDD_BUILD abcdef1011
\group MyGroup
Version,
  A1;  \\field VersionID

ObjectU,
  \\unique-object
  \\required-object
  N1;  \\field NumericFieldA

OtherObject,
  N1;  \\field Again
        """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
Пример #17
0
class TestWritingWholeIDF(unittest.TestCase):
    def setUp(self):
        idd_string = """
    !IDD_Version 13.9.0
    !IDD_BUILD abcdef1018
    \group MyGroup
    Version,
      A1;  \\field VersionID

    MyObject,
           \\min-fields 5
      A1,  \\field Name
           \\required-field
      A2,  \\field Zone Name
           \\required-field
      N1,  \\field A
           \\required-field
           \\units m
      N2,  \\field B
           \\required-field
      N3;  \\field C
           \\default 0.8
           \\required-field
            """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
        self.idd_object = self.idd_structure.get_object_by_type('MyObject')

    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)
Пример #18
0
 def test_valid_idd(self):  # pragma: no cover
     cur_dir = os.path.dirname(os.path.realpath(__file__))
     idd_path = os.path.join(cur_dir, "..", "support_files", "Energy+.idd")
     processor = IDDProcessor()
     ret_value = processor.process_file_given_file_path(idd_path)
     self.assertEquals(57, len(ret_value.groups))
Пример #19
0
class TestIDFFieldValidation(unittest.TestCase):
    def setUp(self):
        idd_string = """
!IDD_Version 12.9.0
!IDD_BUILD abcdef1010
\group MyGroup
Version,
  A1;  \\field VersionID

MyObject,
  N1,  \\field NumericFieldA
       \\minimum 0
       \\maximum 2
       \\required-field
  N2,  \\field NumericFieldB
       \\minimum> 0
       \\maximum< 2
       \\autosizable
  N3;  \\field NumericFieldB
       \\minimum> 0
       \\maximum< 2
       \\autocalculatable
        """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
        self.idd_object = self.idd_structure.get_object_by_type('MyObject')

    def test_valid_idf_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(self.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_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_non_numeric(self):
        idf_string = "Version,12.9;MyObject,A,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_blank_numeric(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), 0)

    def test_non_numeric_but_autosize(self):
        idf_string = "Version,12.9;MyObject,1,AutoSize,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), 0)

    def test_non_numeric_but_autocalculatable(self):
        idf_string = "Version,12.9;MyObject,1,1,AutoCalculate;"
        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_non_numeric_autosize_but_not_allowed(self):
        idf_string = "Version,12.9;MyObject,AutoSize,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_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)

    def test_numeric_too_high_a(self):
        idf_string = "Version,12.9;MyObject,3,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_high_b(self):
        idf_string = "Version,12.9;MyObject,1,2,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_a(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(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_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_whole_idf_valid(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), 0)

    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_whole_idf_one_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), 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)
from pyiddidf.idd_processor import IDDProcessor

file_path = '/home/edwin/Projects/energyplus/repos/4eplus/idd/V8-9-0-Energy+.idd'

idd_processor = IDDProcessor().process_file_given_file_path(file_path)
object_names = []
first_letters = set()
for group in idd_processor.groups:
    for object in group.objects:
        object_names.append(object.name)
        first_letters.add(object.name[0].upper())
found_letters_set = first_letters
full_alphabet_set = set(
    [chr(i).upper() for i in range(ord('a'),
                                   ord('z') + 1)])
missing_letters = full_alphabet_set - found_letters_set
sorted(missing_letters)
print(missing_letters)
Пример #21
0
class TestIDFObjectValidation(unittest.TestCase):
    def setUp(self):
        idd_string = """
!IDD_Version 13.9.0
!IDD_BUILD abcdef1018
\group MyGroup
Version,
  A1;  \\field VersionID

MyObject,
       \\min-fields 5
  A1,  \\field Name
       \\required-field
  A2,  \\field Zone Name
       \\required-field
  N1,  \\field A
       \\required-field
       \\units m
  N2,  \\field B
       \\required-field
  N3;  \\field C
       \\default 0.8
       \\required-field
        """
        self.idd_structure = IDDProcessor().process_file_via_string(idd_string)
        self.idd_object = self.idd_structure.get_object_by_type('MyObject')

    def test_valid_fully_populated_idf_object(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)

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