Beispiel #1
0
 def test_base_class(self):
     weighting = Weighting(("foo", ))
     self.assertEqual(weighting.validator, weighting_validator)
     self.assertEqual(weighting._metadata, weightings)
     weighting.register()
     self.assertTrue(isinstance(weighting.metadata, dict))
     self.assertEqual(weighting.dtype_fields, [])
Beispiel #2
0
def test_weighting_write_invalid_data(reset):
    w = Weighting(("foo",))
    w.register()
    with pytest.raises(ValueError):
        w.write(2)
    with pytest.raises(ValueError):
        w.write([2, 4])
Beispiel #3
0
 def test_write_invalid_data(self):
     w = Weighting(("foo", ))
     w.register()
     with self.assertRaises(ValueError):
         w.write(2)
     with self.assertRaises(ValueError):
         w.write([2, 4])
Beispiel #4
0
def test_weighting_process(reset):
    weighting = Weighting(("foo",))
    weighting.write([42])
    package = load_datapackage(ZipFS(weighting.filepath_processed()))
    print(package.resources)

    data = package.get_resource("foo_matrix_data.data")[0]
    assert np.allclose(data, [42])

    indices = package.get_resource("foo_matrix_data.indices")[0]
    assert np.allclose(indices["row"], 0)
    assert np.allclose(indices["col"], 0)
Beispiel #5
0
    def test_process(self):
        weighting = Weighting(("foo", ))
        weighting.register()
        weighting.write([42])

        fp = os.path.join(projects.dir, "processed",
                          weighting.filename + ".npy")
        array = np.load(fp)

        fieldnames = {x[0] for x in weighting.base_uncertainty_fields}
        self.assertEqual(fieldnames, set(array.dtype.names))
        self.assertEqual(array[0]['amount'], 42)
Beispiel #6
0
def test_weighting_validator(reset):
    weighting = Weighting(("foo",))
    assert weighting.validate([{"amount": 1}])
Beispiel #7
0
def test_weighting_base_class(reset):
    weighting = Weighting(("foo",))
    assert weighting.validator == weighting_validator
    assert weighting._metadata == weightings
    weighting.register()
    assert isinstance(weighting.metadata, dict)
Beispiel #8
0
def test_weighting_write_good_data(reset):
    w = Weighting(("foo",))
    w.register()
    w.write([2])
    w.write([{"amount": 2}])
    w.write([{"amount": 2, "uncertainty type": 0}])
Beispiel #9
0
 def test_validator(self):
     weighting = Weighting(("foo", ))
     self.assertTrue(weighting.validate([{'amount': 1}]))
Beispiel #10
0
 def test_write_good_data(self):
     w = Weighting(("foo", ))
     w.register()
     w.write([2])
     w.write([{'amount': 2}])
     w.write([{'amount': 2, 'uncertainty type': 0}])