Exemple #1
0
 def __init__(self):
     print("Creating new registry")
     self.registries = dict()
     indra_dir = get_indra_home()
     self.db_dir = os.path.join(indra_dir, 'registry', 'db')
     if not os.path.exists(self.db_dir):
         os.mkdir(self.db_dir)
 def test_registry_saved_to_disk(self, dump, load):
     indra_dir = get_indra_home(PA_INDRA_NET)
     file_path = os.path.join(indra_dir, 'registry', 'db',
                              '{}-reg.json'.format(self.exec_key))
     registry[self.exec_key]["name"] = "Abhinav"
     registry.save_reg(self.exec_key)
     self.assertTrue(os.path.exists(file_path))
Exemple #3
0
"""
"""
import json
from unittest import TestCase, main, skip

from APIServer.props_api import get_props
from APIServer.api_utils import ERROR

from lib.utils import PA_INDRA_NET, get_indra_home

BASIC_MODEL_ID = 0
BAD_MODEL_ID = -999
indra_dir = get_indra_home(PA_INDRA_NET)


class TestPropsAPI(TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_get_props(self):
        """
        See if props can be gotten!
        We will try both the error case and a good case.
        """
        ret = get_props(BAD_MODEL_ID, "nonsense")
        print("Ret = ", ret)
        self.assertTrue(ERROR in ret)
        ret = get_props(BASIC_MODEL_ID, indra_dir)
"""
This is the test suite for model_db.py.
It assumes we have a model with ID 0 and module 'basic'.
"""

from unittest import TestCase, skip
from registry import model_db as mdb
from lib.utils import get_indra_home

BASIC_ID = 0
BASIC_MOD = "basic"
indra_dir = get_indra_home()


class ModelDBTestCase(TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_get_models(self):
        self.assertTrue(isinstance(mdb.get_models(indra_dir), list))

    def test_get_model_by_id(self):
        model = mdb.get_model_by_id(BASIC_ID, indra_dir)
        self.assertTrue(model[mdb.MODEL_ID] == BASIC_ID)

    def test_get_model_by_mod(self):
        model = mdb.get_model_by_mod(BASIC_MOD, indra_dir)
        self.assertTrue(model[mdb.MODEL_MOD] == BASIC_MOD)
Exemple #5
0
# import db.menus_db as mdb
from lib.agent import Agent
from lib.utils import get_indra_home

TERMINAL = "terminal"
TEST = "test"
API = "api"
GUI = "gui"
CANT_ASK_TEST = "Can't ask anything of a scripted test"
DEF_STEPS = 1
DEFAULT_CHOICE = '1'
USER_EXIT = -999

MENU_SUBDIR = "lib"
indra_home = get_indra_home()
menu_dir = f"{indra_home}/{MENU_SUBDIR}"
menu_file = "menu.json"
menu_src = menu_dir + "/" + menu_file

ACTIVE = "active"
RADIO_SET = "radio_set"
FUNC = "func"

SCATTER_PLOT = "scatter_plot"
LINE_GRAPH = "line_graph"
BAR_GRAPH = "bar_graph"


def get_menu_json():
    menu_json = None
Exemple #6
0
"""
This module interfaces to the menus database.
"""

import json
import lib.utils as utl

DB_DIR = "db"
MODEL_MENU = "model_menu.json"
MODEL_MENU_PATH = "/" + DB_DIR + "/" + MODEL_MENU
DEBUG_MENU = "debug_menu.json"
DEBUG_MENU_PATH = "/" + DB_DIR + "/" + DEBUG_MENU
RUN_MENU = "run_menu.json"
RUN_MENU_PATH = "/" + DB_DIR + "/" + RUN_MENU

DEF_INDRA_HOME = utl.get_indra_home()


def get_menu(menu_file):
    try:
        with open(menu_file) as file:
            return json.loads(file.read())
    except FileNotFoundError:
        return None


def get_run_menu(indra_dir=DEF_INDRA_HOME):
    """
    Return the model menu.
    """
    return get_menu(indra_dir + RUN_MENU_PATH)
Exemple #7
0
 def __get_pickle_file(self, fname):
     indra_dir = get_indra_home()
     db_dir = os.path.join(indra_dir, 'registry', 'db')
     pickle_file = os.path.join(
         db_dir, '{}-{}-{}.pkl'.format(self.exec_key, self.name, fname))
     return pickle_file