コード例 #1
0
ファイル: test_main.py プロジェクト: anan44/cloud_weather
    def test_read_config_illegal_value_high(self):
        """Tests reading config json file with illegal high value"""
        test_dict = {"polling_interval_in_minutes": 180,
                     "api_key": "Your API key goes here",
                     "days_checked": 20
                     }
        with open("config_test.json", "w") as test_file:
            json.dump(test_dict, test_file)

        with self.assertRaises(ValueError):
            main.read_config("config_test.json")
コード例 #2
0
def test_process_event_pivotal_tracker(mocker):
    mock_client = mocker.patch.object(main.boto3, 'client').return_value
    mock_client.get_parameter.return_value = {
        'Parameter': {
            'Value': 'some secret'
        }
    }
    # called in create_story
    mock_post = mocker.patch.object(requests, 'post')
    # called in _get_current_top_of_backlog
    mock_get = mocker.patch.object(requests, 'get')
    mock_get.return_value.json.return_value = [{'id': 1}]
    # called in _move_to_top_of_backlog
    mock_put = mocker.patch.object(requests, 'put')

    config = main.read_config('config.json.sample')
    with open('test_event_one.json', 'r') as f:
        mock_event = json.load(f)

    rv = main.process_event(config, mock_event)

    mock_post.assert_called()
    mock_get.assert_called()
    mock_put.assert_called()

    assert len(rv) > 0
コード例 #3
0
 def test_check_location_exists_false(self):
     """Tests that check_location is able to verify that provided location
     is supported by OpenWeatherMap API
     """
     point = Observer("qwert123", -2, 11)
     api_key = read_config("config.json")["api_key"]
     self.assertFalse(point.check_location_exists(api_key))
コード例 #4
0
ファイル: test_main.py プロジェクト: anan44/cloud_weather
    def test_read_config(self):
        """Tests reading config json file"""
        config = main.read_config("config_template.json")

        self.assertEqual(config["api_key"], "Your API key goes here")
        self.assertEqual(config["polling_interval_in_minutes"], 180)
        self.assertEqual(config["locations"][0]["name"], "Vantaa")
        self.assertEqual(config["days_checked"], 5)
コード例 #5
0
ファイル: updatebidtest.py プロジェクト: chayes1987/UpdateBid
 def test_read_config(self):
     """
     Tests the read_config function
     :return: Assertion results
     """
     config = read_config()
     self.assertNotEqual(None, config)
     self.assertEqual('tcp://*:2500', config[Config.PUB_ADDR])
     self.assertEqual('tcp://172.31.32.23:2360', config[Config.SUB_ADDR])
     self.assertEqual('BidChanged', config[Config.TOPIC])
     self.assertEqual('https://auctionapp.firebaseio.com',
                      config[Config.FIREBASE_URL])
コード例 #6
0
def test_process_event_targetprocess(mocker):
    mock_client = mocker.patch.object(main.boto3, 'client').return_value
    mock_client.get_parameter.return_value = {
        'Parameter': {
            'Value': 'some secret'
        }
    }
    # called in create_story
    mock_post = mocker.patch.object(requests, 'post')

    config = main.read_config('config.json.sample')
    with open('test_event_two.json', 'r') as f:
        mock_event = json.load(f)

    rv = main.process_event(config, mock_event)

    mock_post.assert_called()

    assert len(rv) > 0
コード例 #7
0
ファイル: test_scripts.py プロジェクト: mchadwick-iqt/SkyScan
def test_read_config():
    """Test read_config()."""
    config = read_config(os.path.join("test", "test_config.ini"))
    assert config["file_names"]["dataset_name"] == "hello_world"
    assert config["file_locations"]["image_directory"] == "foo"
    assert config["file_locations"]["faa_aircraft_db"] == "bar"
コード例 #8
0
def main(checkpoint, config_path, output_dir):
    config = read_config(config_path)

    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

    print('Initializing parameters')
    template_file_path = config['template_fname']
    template_mesh = Mesh(filename=template_file_path)

    print('Generating transforms')
    M, A, D, U = mesh_operations.generate_transform_matrices(
        template_mesh, config['downsampling_factors'])

    D_t = [scipy_to_torch_sparse(d).to(device) for d in D]
    U_t = [scipy_to_torch_sparse(u).to(device) for u in U]
    A_t = [scipy_to_torch_sparse(a).to(device) for a in A]
    num_nodes = [len(M[i].v) for i in range(len(M))]

    print('Preparing dataset')
    data_dir = config['data_dir']
    normalize_transform = Normalize()
    dataset = ComaDataset(data_dir,
                          dtype='test',
                          split='sliced',
                          split_term='sliced',
                          pre_transform=normalize_transform)
    loader = DataLoader(dataset, batch_size=1, shuffle=False, num_workers=1)

    print('Loading model')
    model = Coma(dataset, config, D_t, U_t, A_t, num_nodes)
    checkpoint = torch.load(checkpoint)
    state_dict = checkpoint['state_dict']
    model.load_state_dict(state_dict)
    model.eval()
    model.to(device)

    print('Generating latent')
    data = next(iter(loader))
    with torch.no_grad():
        data = data.to(device)
        x = data.x.reshape(data.num_graphs, -1, model.filters[0])
        z = model.encoder(x)

    print('View meshes')
    meshviewer = MeshViewers(shape=(1, 1))
    for feature_index in range(z.size(1)):
        j = torch.range(-4, 4, step=0.1, device=device)
        new_z = z.expand(j.size(0), z.size(1)).clone()
        new_z[:, feature_index] *= 1 + 0.3 * j

        with torch.no_grad():
            out = model.decoder(new_z)
            out = out.detach().cpu() * dataset.std + dataset.mean

        for i in trange(out.shape[0]):
            mesh = Mesh(v=out[i], f=template_mesh.f)
            meshviewer[0][0].set_dynamic_meshes([mesh])

            f = os.path.join(output_dir, 'z{}'.format(feature_index),
                             '{:04d}.png'.format(i))
            os.makedirs(os.path.dirname(f), exist_ok=True)
            meshviewer[0][0].save_snapshot(f, blocking=True)
コード例 #9
0
 def test_get_forecast(self):
     """Tests that get_forcast is able to get reply from API"""
     point = Observer("Talin", -5, 12)
     api_key = read_config("config.json")["api_key"]
     self.assertEqual(point.get_forecast(3, api_key), 200)