def test(plotgroup_names):
    import topo
    import param
    assert topo.sim.name==sim_name
    assert topo.sim['V1'].nominal_density==8
    assert topo.sim.time()==100

    failing_tests=[]
    for name in plotgroup_names:
        print "\n* Testing plotgroups['%s']:"%name

        sheet = topo.sim['V1']
        _reset_views(sheet)
        plotgroups[name]._exec_pre_plot_hooks()

        filename = resolve_path('tests/data_maptests/%s_t%s_%s.data'%(sim_name,topo.sim.timestr(),
                                                          name.replace(' ','_')))
        print "Reading previous results from %s" % (filename)
        f = open(filename,'r')

        try:
            topo_version,previous_views = pickle.load(f)
        ########################################
        except AttributeError:
            # CEBALERT: code here just to support old data file. Should
            # generate a new one so it's no longer necessary.

            from topo.misc.legacy import preprocess_state

            import topo.base.boundingregion

            def _boundingregion_not_parameterized(instance,state):
                for a in ['initialized', '_name_param_value', 'nopickle']:
                    if a in state:
                        del state[a]

            preprocess_state(topo.base.boundingregion.BoundingRegion,
                             _boundingregion_not_parameterized)

            f.seek(0)
            topo_version,previous_views = pickle.load(f)
        ########################################

        f.close()

        if 'sheet_views' in previous_views[sheet.name]:
            previous_sheet_views = previous_views[sheet.name]['sheet_views']
            for view_name in previous_sheet_views:
                failing_tests += checkclose(sheet.name + " " + view_name,topo_version,
                                            sheet.sheet_views[view_name].view()[0],
                                            previous_sheet_views[view_name].view()[0])

        if 'curve_dict' in previous_views[sheet.name]:
            previous_curve_dicts = previous_views[sheet.name]['curve_dict']
            # CB: need to cleanup var names e.g. val
            for curve_name in previous_curve_dicts:
                for other_param in previous_curve_dicts[curve_name]:
                    for val in previous_curve_dicts[curve_name][other_param]:
                        failing_tests += checkclose("%s %s %s %s" %(sheet.name,curve_name,other_param,val),topo_version,
                                                    sheet.curve_dict[curve_name][other_param][val].view()[0],
                                                    previous_curve_dicts[curve_name][other_param][val].view()[0])

    if failing_tests != []: raise AssertionError, "Failed map tests: %s" % (failing_tests)
def test(plotgroup_names):
    import topo
    assert topo.sim.name == sim_name
    assert topo.sim['V1'].nominal_density == 8
    assert topo.sim.time() == 100

    failing_tests = []
    for name in plotgroup_names:
        print "\n* Testing plotgroups['%s']:" % name

        sheet = topo.sim['V1']
        _reset_views(sheet)
        plotgroups[name]._exec_pre_plot_hooks()

        filename = resolve_path(
            'tests/data_maptests/%s_t%s_%s.data' %
            (sim_name, topo.sim.timestr(), name.replace(' ', '_')))
        print "Reading previous results from %s" % (filename)
        f = open(filename, 'r')

        try:
            topo_version, previous_views = pickle.load(f)
        ########################################
        except AttributeError:
            # CEBALERT: code here just to support old data file. Should
            # generate a new one so it's no longer necessary.

            from topo.misc.legacy import preprocess_state

            import topo.base.boundingregion

            def _boundingregion_not_parameterized(instance, state):
                for a in ['initialized', '_name_param_value', 'nopickle']:
                    if a in state:
                        del state[a]

            preprocess_state(topo.base.boundingregion.BoundingRegion,
                             _boundingregion_not_parameterized)

            f.seek(0)
            topo_version, previous_views = pickle.load(f)
        ########################################

        f.close()

        if 'sheet_views' in previous_views[sheet.name]:
            previous_sheet_views = previous_views[sheet.name]['sheet_views']
            for view_name in previous_sheet_views:
                failing_tests += checkclose(
                    sheet.name + " " + view_name, topo_version,
                    sheet.views.maps[view_name].top.data,
                    previous_sheet_views[view_name].view()[0])

        if 'curve_dict' in previous_views[sheet.name]:
            previous_curve_dicts = previous_views[sheet.name]['curve_dict']
            # CB: need to cleanup var names e.g. val
            time, duration = (topo.sim.time(), 1.0)
            for curve_name in previous_curve_dicts:
                for other_param in previous_curve_dicts[curve_name]:
                    other_param_val = unit_value(other_param)[-1]
                    for val in previous_curve_dicts[curve_name][other_param]:
                        new_curves = sheet.views.curves[
                            curve_name.capitalize()]
                        new = new_curves[time, duration, other_param_val -
                                         0.01:other_param_val + 0.01,
                                         val].values()[0].data
                        old = previous_curve_dicts[curve_name][other_param][
                            val].view()[0]
                        failing_tests += checkclose(
                            "%s %s %s %s" %
                            (sheet.name, curve_name, other_param, val),
                            topo_version, new, old)

    if failing_tests != []:
        raise AssertionError, "Failed map tests: %s" % (failing_tests)
def test(plotgroup_names):
    import topo
    assert topo.sim.name==sim_name
    assert topo.sim['V1'].nominal_density==8
    assert topo.sim.time()==100

    failing_tests=[]
    for name in plotgroup_names:
        print "\n* Testing plotgroups['%s']:"%name

        sheet = topo.sim['V1']
        _reset_views(sheet)
        plotgroups[name]._exec_pre_plot_hooks()

        filename = resolve_path('tests/data_maptests/%s_t%s_%s.data'%(sim_name,topo.sim.timestr(),
                                                          name.replace(' ','_')))
        print "Reading previous results from %s" % (filename)
        f = open(filename,'r')

        try:
            topo_version,previous_views = pickle.load(f)
        ########################################
        except AttributeError:
            # PRALERT: Code to allow loading of old data files after
            # boundingregion was moved to holoviews.
            import sys
            from holoviews.core import boundingregion
            sys.modules['imagen.boundingregion'] = boundingregion


            # CEBALERT: code here just to support old data file. Should
            # generate a new one so it's no longer necessary.

            from topo.misc.legacy import preprocess_state

            import topo.base.boundingregion

            def _boundingregion_not_parameterized(instance,state):
                for a in ['initialized', '_name_param_value', 'nopickle']:
                    if a in state:
                        del state[a]

            preprocess_state(topo.base.boundingregion.BoundingRegion,
                             _boundingregion_not_parameterized)

            f.seek(0)
            topo_version,previous_views = pickle.load(f)
        ########################################

        f.close()

        if 'sheet_views' in previous_views[sheet.name]:
            previous_sheet_views = previous_views[sheet.name]['sheet_views']
            for view_name in previous_sheet_views:
                failing_tests += checkclose(sheet.name + " " + view_name,topo_version,
                                            sheet.views.Maps[view_name].last.data,
                                            previous_sheet_views[view_name].view()[0])

        if 'curve_dict' in previous_views[sheet.name]:
            previous_curve_dicts = previous_views[sheet.name]['curve_dict']
            # CB: need to cleanup var names e.g. val
            time, duration = (topo.sim.time(), 1.0)
            for curve_name in previous_curve_dicts:
                for other_param in previous_curve_dicts[curve_name]:
                    other_param_val = unit_value(other_param)[-1]
                    for val in previous_curve_dicts[curve_name][other_param]:
                        new_curves = sheet.views.Curves[curve_name.capitalize()+"Tuning"]
                        new_curves = new_curves.clone(key_dimensions=[d(values=[]) for d in new_curves.key_dimensions])
                        new = new_curves[time, duration, other_param_val-0.01:other_param_val+0.01, val].values()[0].data
                        old = previous_curve_dicts[curve_name][other_param][val].view()[0]
                        failing_tests += checkclose("%s %s %s %s" %(sheet.name,curve_name,other_param,val),
                                                    topo_version, new, old)

    if failing_tests != []: raise AssertionError, "Failed map tests: %s" % (failing_tests)
def test(plotgroup_names):
    import topo
    import param
    assert topo.sim.name==sim_name
    assert topo.sim['V1'].nominal_density==8
    assert topo.sim.time()==100
    
    for name in plotgroup_names:
        print "\n* Testing plotgroups['%s']:"%name

        sheet = topo.sim['V1']
        _reset_views(sheet)
        plotgroups[name]._exec_pre_plot_hooks()

        f = open(resolve_path('tests/%s_t%s_%s.data'%(sim_name,topo.sim.timestr(),
                                                      name.replace(' ','_'))),'r')

        try:
            topo_version,previous_views = pickle.load(f)
        ########################################
        except AttributeError:
            # CEBALERT: code here just to support old data file. Should
            # generate a new one so it's no longer necessary.
            
            from topo.misc.legacy import preprocess_state

            import topo.base.boundingregion

            def _boundingregion_not_parameterized(instance,state):
                for a in ['initialized', '_name_param_value', 'nopickle']:
                    if a in state:
                        del state[a]

            preprocess_state(topo.base.boundingregion.BoundingRegion,
                             _boundingregion_not_parameterized)
    
            f.seek(0)
            topo_version,previous_views = pickle.load(f)
        ########################################
            
        f.close()

        if 'sheet_views' in previous_views[sheet.name]:
            previous_sheet_views = previous_views[sheet.name]['sheet_views']
            for view_name in previous_sheet_views:
                assert_array_almost_equal(sheet.sheet_views[view_name].view()[0],
                                          previous_sheet_views[view_name].view()[0],
                                          12)
                print '...'+view_name+' array is unchanged since data was generated (%s)'%topo_version

        if 'curve_dict' in previous_views[sheet.name]:
            previous_curve_dicts = previous_views[sheet.name]['curve_dict']
            # CB: need to cleanup var names e.g. val
            for curve_name in previous_curve_dicts:
                for other_param in previous_curve_dicts[curve_name]:
                    for val in previous_curve_dicts[curve_name][other_param]:

                        assert_array_almost_equal(sheet.curve_dict[curve_name][other_param][val].view()[0],
                                                  previous_curve_dicts[curve_name][other_param][val].view()[0],
                                                  12)
                        print "...%s %s %s array is unchanged since data was generated (%s)"%(curve_name,other_param,val,topo_version)