def test_create_instance_with_invalid_configs(self):

        with self.subTest("with no local storage"):
            with self.assertRaises(InvalidConfigError):
                config = TestConfig()
                config.LOCAL_STORAGE_LOCATION = ''

                FileSystemStorage(config)

        with self.subTest("with a relative path"):
            with self.assertRaises(InvalidConfigError):
                config = TestConfig()
                config.LOCAL_STORAGE_LOCATION = '../../etc'

                FileSystemStorage(config)

        with self.subTest("with None config"):
            with self.assertRaises(InvalidConfigError):
                FileSystemStorage(None)

        with self.subTest("with valid config"):

            config = TestConfig()

            storage = FileSystemStorage(config)

            from decouple import config
            BASE_DIR = os.path.join(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                '/test')

            self.assertEqual(storage.config.LOCAL_STORAGE_LOCATION,
                             config('LOCAL_STORAGE_LOCATION'))
Beispiel #2
0
def client():
    logging.log(logging.INFO, TestConfig().SQLALCHEMY_DATABASE_URI)

    app = create_app(TestConfig())
    client = app.test_client()

    yield client
Beispiel #3
0
def app(request):
    """
    Returns session-wide application.
    """
    logging.log(logging.INFO, TestConfig().SQLALCHEMY_DATABASE_URI)
    app = create_app(TestConfig())

    return app
Beispiel #4
0
 def setUp(self):
     test_config = TestConfig()
     self.app = create_app(test_config)
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     db.create_all()
Beispiel #5
0
def test_method(gpu):
	os.environ["CUDA_VISIBLE_DEVICES"] = gpu
	config = TestConfig()
	# config.checkpoints_dir = "/media/data2/xyz_data/CelebA_full/full_third_2019-6-19_0.9135_ckp"

	print("{} model was initialized".format(config.model_name))
	# dataset is test set or val
	config.isTest = True
	dataset = create_dataset(config=config)
	model = create_model(config)
	for j in range(0, 102, 1):
		config.load_iter = j
		model.setup()
		model.clear_precision()
		if config.eval:
			model.eval()
		dataset_size = len(dataset)

		print("test dataset len: %d " % dataset_size)
		total_iter = int(dataset_size / config.batch_size)
		model.set_validate_size(dataset_size)
		# fc_feature = np.zeros((dataset_size, 2048))
		# label = np.zeros((dataset_size, 40))
		for i, data in enumerate(dataset):
			model.set_input(data)
			print("[%s/%s]" % (i, total_iter))
			model.test()

		print(model.get_model_precision())
		print(model.get_model_class_balance_precision())
		print("mean accuracy: {}".format(torch.mean(model.get_model_precision())))
		print("class_balance accuracy: {}".format(torch.mean(model.get_model_class_balance_precision())))
Beispiel #6
0
def validate(model):
    validate_config = TestConfig()
    validate_config.isTest = True

    logger = validate_config.test_logger
    logger.info("--------------------------------------------------------")
    logger.debug("test the model using the validate dataset")

    validate_dataset = create_dataset(validate_config)
    model.eval()
    model.clear_precision()
    model.set_validate_size(len(validate_dataset))
    logger.info("validate dataset len: %d " % len(validate_dataset))
    validate_total_iter = int(
        len(validate_dataset) / validate_config.batch_size)

    for j, valida_data in enumerate(validate_dataset):
        model.set_input(valida_data)
        logger.debug("[%s/%s]" % (j, validate_total_iter))
        model.test()
    # output the precision
    logger.debug(model.get_model_precision())
    logger.debug(model.get_model_class_balance_precision())
    logger.info("mean accuracy: {}".format(
        torch.mean(model.get_model_precision())))
    logger.info("class_balance accuracy: {}".format(
        torch.mean(model.get_model_class_balance_precision())))
    logger.debug("validate mode end")
    logger.info("--------------------------------------------------------")
    def setUp(self):

        #Config
        config = TestConfig()

        #NoSuchKey Error
        error = {
            'Error': {
                'Code': 'NoSuchKey',
                'Message': 'The specified key does not exist.',
                'Key': 'd20b1c38-2f5f-4b48-b604-eb90f82ff800'
            },
            'ResponseMetadata': {
                'HTTPStatusCode': 404,
                'RetryAttempts': 0
            }
        }

        #Mock
        mock = MagicMock()
        mock.get_object(Bucket=config.BUCKET_NAME,
                        Key='d20b1c38-2f5f-4b48-b604-eb90f82ff800')
        mock.get_object.side_effect = ClientError(error, 'GetObject')

        config.S3 = mock

        #Storage
        self.storage = AWSStorage(config)
        self.config = config
Beispiel #8
0
def get_config():
    if FLAGS.model == "small":
        return SmallConfig()
    elif FLAGS.model == "test":
        return TestConfig()
    else:
        raise ValueError("Invalid model: %s", FLAGS.model)
Beispiel #9
0
def gatebot():
    gatebot = GateBot(TestConfig())
    gatebot.config.QUESTIONS_PER_QUIZ = 3
    gatebot.config.CORRECT_ANSWERS_REQUIRED = 2

    Base.metadata.create_all()

    return gatebot
Beispiel #10
0
def database():
    from mox.data import Database
    config = TestConfig()
    db = Database(config)
    db.open()
    yield db
    db.rollback()
    db.close()
Beispiel #11
0
def main(env: str = None):
    if env == 'prod':
        config = ProductionConfig()
    elif env == 'test':
        config = TestConfig()
    else:
        print("Usage: python3 deploy.py --env=prod|test")
        return

    ecs = ECS(config_obj=config)
    ecs.run()
    def test_create_instance_with_invalid_configs(self):

        with self.subTest("with no bucket name"):
            with self.assertRaises(InvalidConfigError):
                config = TestConfig()
                config.BUCKET_NAME = ''

                AWSStorage(config)

        with self.subTest("with no key"):
            with self.assertRaises(InvalidConfigError):
                config = TestConfig()
                config.KEY = ''

                AWSStorage(config)

        with self.subTest("with no secret key"):
            with self.assertRaises(InvalidConfigError):
                config = TestConfig()
                config.SECRET_KEY = ''

                AWSStorage(config)

        with self.subTest("with None config"):
            with self.assertRaises(InvalidConfigError):
                AWSStorage(None)

        with self.subTest("with valid config"):

            config = TestConfig()

            storage = AWSStorage(config)

            from decouple import config
            BASE_DIR = os.path.join(
                os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                '/test')

            self.assertEqual(storage.config.BUCKET_NAME, config('BUCKET_NAME'))
            self.assertEqual(storage.config.KEY, config('KEY'))
            self.assertEqual(storage.config.SECRET_KEY, config('SECRET_KEY'))
Beispiel #13
0
def client():
    from mox import create_app, Dependencies

    config = TestConfig()
    deps = Dependencies(config)
    client = create_app(deps).test_client()
    client.database = deps.database

    yield client

    deps.database.rollback()
    deps.database.close()
    def setUp(self):
        #Config
        self.config = TestConfig()

        #Storage
        self.storage = FileSystemStorage(self.config)

        #Temp File
        self.file = tempfile.TemporaryFile(mode='w+b')
        self.file.write(b'It is a file!')
        self.file.seek(0)
        self.raw_file = self.file.read()
def create_app() -> Flask:
    """Create task runner app."""
    # pylint: disable=W0621
    app = Flask(__name__)

    if app.config["ENV"] == "development":
        try:
            from config_cust import DevConfig as DevConfigCust

            app.config.from_object(DevConfigCust())
        except ImportError:
            from config import DevConfig

            app.config.from_object(DevConfig())

    elif app.config["ENV"] == "test":
        try:
            from config_cust import (
                TestConfig as TestConfigCust,  # type: ignore[attr-defined]
            )

            app.config.from_object(TestConfigCust())
        except ImportError:
            from config import TestConfig

            app.config.from_object(TestConfig())

    else:
        try:
            from config_cust import Config as ConfigCust

            app.config.from_object(ConfigCust())
        except ImportError:
            from config import Config

            app.config.from_object(Config())

    db.init_app(app)

    executor.init_app(app)

    redis_client.init_app(app)

    with app.app_context():
        # pylint: disable=C0415

        from runner.web import filters, web

        app.register_blueprint(web.web_bp)
        app.register_blueprint(filters.filters_bp)

        return app
Beispiel #16
0
def test_file_logging():
    ''' Make sure file logging is set up '''
    file_config = TestConfig()
    file_config.TESTING = False
    file_config.FLASK_LOG_FILE = "/dev/null"
    file_config.FLASK_LOG_LEVEL = "INFO"
    with LogCapture() as test_logger:
        create_app(file_config)
        test_logger.check_present(
            ('app', 'INFO', 'NGS360 loading'),
            ('app', 'INFO', 'Setting up file logging to /dev/null'),
            ('app', 'INFO', 'NGS360 loaded.')
        )
    def setUp(self):

        #Config
        config = TestConfig()

        #Mock
        mock = MagicMock()
        mock.delete_object(Bucket=config.BUCKET_NAME,
                           Key='d20b1c38-2f5f-4b48-b604-eb90f82ff800')

        config.S3 = mock

        #Storage
        self.storage = AWSStorage(config)
        self.config = config
Beispiel #18
0
def create_app(type="app", test=False):
    app = Flask(__name__)

    cfg = DevConfig()
    if test:
        cfg = TestConfig()

    app.config.from_object(cfg)
    configure_celery(app, tasks.celery)

    init_mongo(app)
    register_error_handlers(app)
    register_routes(app)

    return app if type == "app" else tasks.celery
Beispiel #19
0
def test_email_logging():
    ''' Make sure email logging is set up '''
    email_config = TestConfig()
    email_config.TESTING = False
    email_config.MAIL_SERVER = "xyz"
    email_config.MAIL_PORT = 1
    email_config.MAIL_USERNAME = "******"
    email_config.MAIL_PASSWORD = ''
    email_config.MAIL_USE_TLS = 1
    email_config.ADMINS = "abc"
    with LogCapture() as test_logger:
        create_app(email_config)
        test_logger.check_present(
            ('app', 'INFO', 'NGS360 loading'),
            ('app', 'INFO', 'Setting up email logger'),
            ('app', 'INFO', 'NGS360 loaded.')
        )
Beispiel #20
0
def create_app(test_config=False):
    app = Flask(__name__)

    config = TestConfig() if test_config else BaseConfig()
    app.config.from_object(config)

    app.register_blueprint(api_blueprint)

    jwt = JWTManager()
    jwt.init_app(app)

    db.init_app(app)
    migrate = Migrate(app, db)

    logging.basicConfig(
        format='%(asctime)s - %(name)s:%(message)s',
        filename=Path(__file__, '../../app.log').resolve(),
        level=logging.DEBUG,
    )

    return app
    def setUp(self):

        #Temp File
        self.file = tempfile.TemporaryFile(mode='w+b')
        self.file.write(b'It is a file!')
        self.file.seek(0)
        self.raw_file = self.file.read()

        #Config
        config = TestConfig()

        #Mock
        mock = MagicMock()
        mock.put_object(Bucket=config.BUCKET_NAME,
                        Key='d20b1c38-2f5f-4b48-b604-eb90f82ff800',
                        Body=b'It is a file!')

        config.S3 = mock

        #Storage
        self.storage = AWSStorage(config)
        self.config = config
Beispiel #22
0
def app():
    ''' Set test App context '''
    app = create_app()
    config = TestConfig()
    app.config.from_object(config)
    return app
    def setUp(self):
        #Config
        self.config = TestConfig()

        #Storage
        self.storage = FileSystemStorage(self.config)
Beispiel #24
0
def app():
    """ Application Ficture """
    app = create_app()
    config = TestConfig()
    app.config.from_object(config)
    return app
Beispiel #25
0
 def setUp(self):
     self.verifyString = 'test'
     self.config = TestConfig()
Beispiel #26
0
    def __init__(self, burnin, enable_eth_tests, enable_modem_test=0, **kw):
        self._burnin = burnin
        self._preflight_done = 0

        # DO NOT CHANGE THE ORDER OF THESE THREE ITEMS!  Thank you!
        self._config = TestConfig(burnin, '/etc/hw_test.conf')
        self._hw_info = HardwareInfo()
        self._logger = TestLogger(burnin, self._hw_info.serialno())

        self._bootlog_tester = None
        self._car_tester = None
        self._dallas_tester = None
        self._eth_tester = None
        self._i2c_tester = None
        self._mem_tester = None
        self._stressmemtester = None
        self._modem_tester = None
        self._serial_tester = None
        self._usb_tester = None
        self._enabled_tests = 0

        model = self._hw_info.model()
        if kw.get('bootlog', True):
            self._bootlog_tester = BootlogTester(self._config, self._hw_info,
                                                 self._logger)
            self._enabled_tests += 1
        if kw.get('ram', True):
            self._mem_tester = MemoryTester(self._config, self._hw_info,
                                            self._logger)
            self._enabled_tests += 1
        # do not perform stress test unless called for explicitly.
        if kw.get('ramstress', False):
            self._stressmemtester = MemoryTester(self._config, self._hw_info,
                                                 self._logger, True)
            self._enabled_tests += 1
        if enable_eth_tests and kw.get('ethernet', True):
            self._eth_tester = NetworkTester(self._config, self._hw_info,
                                             self._logger)
            self._enabled_tests += 1
        if not model in ('TSWS', 'PC', 'Unknown', ''):
            self._avr_copro = avr()
            if kw.get('serial', True):
                self._serial_tester = SerialTester(self._config, self._hw_info,
                                                   self._logger)
                self._enabled_tests += 1
        if model in ('1200', '2400', '1500', '2500'):
            if kw.get('relayscounters', True):
                self._car_tester = CountersAndRelaysTester(
                    self._config, self._hw_info, self._logger, self._avr_copro)
                self._enabled_tests += 1
            if kw.get('dallas', True):
                self._dallas_tester = DallasTester(self._config, self._hw_info,
                                                   self._logger,
                                                   self._avr_copro)
                self._enabled_tests += 1
        if model in ('1500', '2500') and kw.get('i2c', True):
            self._i2c_tester = I2CTester(self._config, self._hw_info,
                                         self._logger)
            self._enabled_tests += 1
        if self._hw_info.model() in ('2400', '2500') and kw.get('usb', True):
            self._usb_tester = USBTester(self._config, self._hw_info,
                                         self._logger)
            self._enabled_tests += 1
        return
Beispiel #27
0
def app():
    app = create_app()
    config = TestConfig()
    app.config.from_object(config)
    return app
def create_app() -> Flask:
    """Create task runner app."""
    # pylint: disable=W0621
    app = Flask(__name__)

    if app.config["ENV"] == "development":
        try:
            from config_cust import DevConfig as DevConfigCust

            app.config.from_object(DevConfigCust())
        except ImportError:
            from config import DevConfig

            app.config.from_object(DevConfig())

    elif app.config["ENV"] == "test":
        try:
            from config_cust import (
                TestConfig as TestConfigCust,  # type: ignore[attr-defined]
            )

            app.config.from_object(TestConfigCust())
        except ImportError:
            from config import TestConfig

            app.config.from_object(TestConfig())

    else:
        try:
            from config_cust import Config as ConfigCust

            app.config.from_object(ConfigCust())
        except ImportError:
            from config import Config

            app.config.from_object(Config())

    db.init_app(app)

    # pylint: disable=W0611
    from scheduler import maintenance  # noqa: F401

    with contextlib.suppress(SchedulerAlreadyRunningError):
        # pytest imports twice, this will catch on the second import.
        atlas_scheduler.init_app(app)

    logging.basicConfig(level=logging.WARNING)

    with app.app_context():
        # pylint: disable=W0611
        if atlas_scheduler.running is False:
            # pytest imports twice. this will save us on the
            # second import.
            atlas_scheduler.start()

        # pylint: disable=C0415
        from apscheduler.events import (
            EVENT_JOB_ADDED,
            EVENT_JOB_ERROR,
            EVENT_JOB_EXECUTED,
            EVENT_JOB_MISSED,
            EVENT_JOB_REMOVED,
            EVENT_JOB_SUBMITTED,
        )

        from scheduler import web
        from scheduler.events import (
            job_added,
            job_error,
            job_executed,
            job_missed,
            job_removed,
            job_submitted,
        )

        app.register_blueprint(web.web_bp)

        if app.config["ENV"] == "test":
            logging.getLogger("apscheduler").setLevel(logging.INFO)
        else:
            logging.getLogger("apscheduler").setLevel(logging.ERROR)

        atlas_scheduler.add_listener(job_missed, EVENT_JOB_MISSED)
        atlas_scheduler.add_listener(job_error, EVENT_JOB_ERROR)
        atlas_scheduler.add_listener(job_executed, EVENT_JOB_EXECUTED)
        atlas_scheduler.add_listener(job_added, EVENT_JOB_ADDED)
        atlas_scheduler.add_listener(job_removed, EVENT_JOB_REMOVED)
        atlas_scheduler.add_listener(job_submitted, EVENT_JOB_SUBMITTED)

        @app.errorhandler(404)
        @app.errorhandler(500)
        def error_message(error: str) -> Response:
            """Return error page for 404 and 500 errors including the specific error message."""
            return make_response(jsonify({"error": str(error)}), 404)

        return app
Beispiel #29
0
            X = X[:, :, ::-1]

            X = np.expand_dims(X, axis=0)
            X = X.astype('float32')
            X -= self.X_mean
            X /= 255.0

            return self.model.predict(X)[0]

face_dataset = intrusion_data(csv_file='interpolated_2188to16447_attack_a_0p2_0p9_9982.csv',root_dir='/home/pi/new_try_raspberry_pi--/chen_data_try/chen_new_try/chen_new_data',cs=1,transform=transforms.Compose([transforms.Resize(256),transforms.RandomResizedCrop(224),transforms.ToTensor()]))
test_dataset=intrusion_data(csv_file='interpolated_2188to16447_attack_a_0p2_0p9_4280.csv',root_dir='/home/pi/new_try_raspberry_pi--/chen_data_try/chen_new_try/chen_new_data',cs=1,transform=transforms.Compose([transforms.Resize(256),transforms.RandomResizedCrop(224),transforms.ToTensor()]))

dataloader = DataLoader(face_dataset, batch_size=1, shuffle=False)
test_loader = DataLoader(test_dataset, batch_size=1, shuffle=False)

config = TestConfig()

ch = config.num_channels
row = config.img_height
col = config.img_width
model_org = create_comma_model_large_dropout(row, col, ch, load_weights=True)

model = Model(model_org,
              "data/X_train_gray_diff2_mean.npy")

net = mynet()

criterion = F.nll_loss
optimizer = optim.Adam(net.parameters(), lr=0.01)

def accuracy(act , out):
Beispiel #30
0
                type=str,
                required=True,
                help="Image to perform object recognition on.")
ap.add_argument("-m",
                "--model",
                default="data/mask_rcnn_coco.h5",
                type=str,
                help="Model weights for Mask R-CNN model.")
ap.add_argument("-o",
                "--object-detection",
                action="store_true",
                help="Perform object detection using Mask R-CNN model.")
args = vars(ap.parse_args())

# Define and load model
rcnn = MaskRCNN(mode='inference', model_dir='./', config=TestConfig())

rcnn.load_weights(args["model"], by_name=True)

img = load_img(args["image"])
img_pixels = img_to_array(img)

results = rcnn.detect([img_pixels], verbose=0)
r = results[0]

if args["object_detection"]:
    print("[INFO] Performing object detection using display_instances...")

    # define 81 classes that the coco model knowns about
    class_names = load_coco_classes('data/coco_classes.txt')