def test_getreferences():
    """py.test for getreferences"""
    thedata = (("zone".upper(), 1, ['ZoneNames',
             'OutFaceEnvNames',
             'ZoneAndZoneListNames',
             'AirflowNetworkNodeAndZoneNames']
             ), # key, fieldid, refs
     ("FenestrationSurface:Detailed".upper(), 1, ['SubSurfNames',
            'SurfAndSubSurfNames',
            'AllHeatTranSurfNames',
            'OutFaceEnvNames',
            'AllHeatTranAngFacNames',
            'RadGroupAndSurfNames',
            'SurfGroupAndHTSurfNames',
            'AllShadingAndHTSurfNames']
              ), # key, fieldid, refs
    )
    fname = StringIO("")
    data, commdct = readidf.readdatacommdct(fname, iddV6_0.theidd,
                                                        iddV6_0.commdct)
    theidd = iddV6_0.theidd
    idd = eplus_functions.Idd(commdct, iddV6_0.commlst, theidd, iddV6_0.block)
    idfw = eplus_functions.IdfWrapper(data, idd)
    for key, fieldid, refs in thedata:
        anobject = eplus_functions.makeanobject(data, theidd, commdct, 
                                            key, objname="azone")
        data.dt[key].append(anobject)
        result = eplus_functions.getreferences(idfw, key, fieldid)
        assert result == refs
def test_newname2references_inner():
    """py.test for newname2references_inner"""
    # a zone name is changed. It is refered by lights and people.
    # test if the reference in lights and people also change        
    fname = StringIO("")
    data, commdct = readidf.readdatacommdct(fname, iddV6_0.theidd,
                                                        iddV6_0.commdct)
    theidd = iddV6_0.theidd
    idd = eplus_functions.Idd(commdct, iddV6_0.commlst, theidd, iddV6_0.block)
    idfw = eplus_functions.IdfWrapper(data, idd)
    # - 
    zonekey = 'zone'.upper()
    lightkey = 'lights'.upper()
    peoplekey = 'people'.upper()
    keys = [zonekey, lightkey, peoplekey]
    keys = keys + keys
    names = ['z1', 'l1', 'p1', 'z2', 'l2', 'p2']
    for key, name  in zip(keys, names):
        anobject = eplus_functions.makeanobject(data, theidd, commdct, 
                                                    key, objname="name")
        data.dt[key].append(anobject)
    data.dt[lightkey][0][2] = 'z1'
    data.dt[peoplekey][0][2] = 'z1'
    data.dt[lightkey][1][2] = 'z2'
    data.dt[peoplekey][1][2] = 'z2'
    oldname, newname = 'z1', 'zz1'
    # = 
    refs = eplus_functions.getreferences(idfw, zonekey, 1)
    reflist = eplus_functions.getReferenceObjectList(idfw, refs)
    # - 
    data.dt[zonekey][0][1] = newname
    eplus_functions.newname2references_inner(idfw, reflist, oldname, newname)
    assert data.dt[lightkey][0][2] == newname
    assert data.dt[peoplekey][0][2] == newname
    assert data.dt[lightkey][1][2] == 'z2'
    assert data.dt[peoplekey][1][2] == 'z2'