Exemplo n.º 1
0
 def request(self, method, url, **args):
     args["headers"] = config.get_test_config().headers.copy()
     if "token" in args:
         args["headers"]["Authorization"] = f'Bearer {args["token"]}'
         del args["token"]
     result = super().request(method, url, **args)
     ellipsed_headers = {}
     MAX_LEN = 15
     for header, val in args["headers"].items():
         ellipsed_headers[header] = (val[:MAX_LEN] +
                                     ".." if len(val) > MAX_LEN else val)
     print()
     print("->>", method.upper(), url)
     log.info(f"->> {method.upper()} {url}")
     if ellipsed_headers:
         print("    HTTP headers:", pformat(ellipsed_headers))
         log.info(f"    HTTP headers: {pformat(ellipsed_headers)}")
     if "params" in args:
         print("Query params:", args["params"])
         log.info(f'Query params: {args["params"]}')
     if "json" in args:
         print("Request body:", args["json"])
         log.info(f'Request body: {args["json"]}')
     print("<<-", result.status_code)
     log.info(f"<<- {result.status_code}")
     try:
         pprint(result.json())
         log.info(pformat(result.json()))
     except Exception:
         print(result.text)
         log.info(result.text)
     return result
Exemplo n.º 2
0
def client():
    """
    Client to call API from tests.
    Use FASTAPI TestClient to test local server code without actual HTTP connection.
    If `--host` use `requests` for real HTTP requests.
    """
    if config.get_test_config().host is None:
        return TextClientWithTools(app.main.app)
    else:
        return TextClientExtWithTools()
from web3.auto import w3

import config
from db import Database
from meeting_contract_helper import MeetingContractHelper
from model import Meeting

c = config.get_test_config()
db = Database(c["database"]["db_name"], c["database"]["ip"],
              c["database"]["port"])

# IMPORTANT: MAKE SURE ETHEREUM NODE (OR GANACHE) IS RUNNING AND CONFIGURED IN config.json !!


def test_meeting_contract_deployment():
    mch = MeetingContractHelper(c)
    meeting = Meeting.parse(db.get_all_meetings()[0])
    contract_addr = mch.new_meeting_contract(meeting)

    mdt_meeting = w3.eth.contract(
        address=contract_addr,
        abi=mch.contract_abi,
    )

    assert mdt_meeting.functions.getMeetingId().call() == meeting.id


def test_meeting_contract_set_hash():
    mch = MeetingContractHelper(c)
    meeting = Meeting.parse(db.get_all_meetings()[0])
    contract_addr = mch.new_meeting_contract(meeting)
Exemplo n.º 4
0
import os

os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'

import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.utils.data as data
from config import get_test_config
from data import UNetData
from models import UNet3D
from utils import get_unit_diamond_vertices, save_loss_plot, regression_classification_loss, point_wise_L1_loss, axis_aligned_miou, get_output_from_prediction, get_output_from_prediction_new, unet_loss, point_wise_mse_loss

root_path = '../UNet/'

cfg = get_test_config(root_path)
os.environ['CUDA_VISIBLE_DEVICES'] = cfg['cuda_devices']
use_gpu = torch.cuda.is_available()

data_set = UNetData(cfg=cfg['dataset'], root_path=root_path, part='test')
data_loader = data.DataLoader(data_set,
                              batch_size=1,
                              num_workers=4,
                              shuffle=False,
                              pin_memory=False)


def test_model(model):
    model.eval()
    criterion = nn.L1Loss()
    running_loss = 0.0
Exemplo n.º 5
0
            i[1] if i[1].shape[-1] == self.max_faces else F.pad(
                i[1], pad=(0, 1), mode='constant', value=0) for i in batch
        ])
        normals = torch.stack([
            i[2] if i[2].shape[-1] == self.max_faces else F.pad(
                i[2], pad=(0, 1), mode='constant', value=0) for i in batch
        ])
        neighbor_index = torch.stack([
            i[3] if i[3].shape[0] == self.max_faces else torch.cat(
                [i[3], torch.zeros(1, 3)]) for i in batch
        ]).type(torch.LongTensor)
        filename = [i[5] for i in batch]
        return centers, corners, normals, neighbor_index, filename


cfg = get_test_config()
cfg['dataset']['test_root'] = args.test_root
cfg['dataset']['max_faces'] = args.num_faces

os.environ['CUDA_VISIBLE_DEVICES'] = cfg['cuda_devices']

data_set = Testset(cfg=cfg['dataset'])
data_loader = data.DataLoader(data_set,
                              batch_size=1,
                              num_workers=4,
                              shuffle=True,
                              pin_memory=True)


def inference(model):
    embed_dict = {}
Exemplo n.º 6
0
                    print(m,n)
                    imshow(bat_opt[i], str='im_%d_ker_%d' % (m, n), dir=self.args.test_save_dir + name + '/')


    def load_model(self):
        ckp = torch.load(self.args.test_ckp_dir, map_location=lambda storage, loc: storage.cuda(self.args.gpu_idx))
        self.net.load_state_dict(ckp['model'])
        return ckp

    def eval_net(self, bl, *args):
        with torch.no_grad():
            self.net.eval()
            bl = bl.cuda()
            db = self.net(bl,*args)
        return db


if __name__ == "__main__":
    args = get_test_config()
    torch.cuda.set_device(args.gpu_idx)
    net = vem_deblur_model(args).cuda()

    test_dset = {}
    for dset in args.dataset_name:
        for sigma in args.test_sigma:
            test_dset[dset + '_' + str(sigma)] = Test_Dataset(args.test_sp_dir[dset], args.test_bl_dir[dset + '_' + str(sigma)], args.ker_dir)

    test = Tester(args, net, test_dset)
    test()
    print('[*] Finish!')
Exemplo n.º 7
0
 def url(relative_url):
     if config.get_test_config().host.startswith("http"):
         return urljoin(config.get_test_config().host, relative_url)
     else:
         return urljoin(f"http://{config.get_test_config().host}",
                        relative_url)