def test_save_creates_correct_output(self, tmpdir, empty_network):
        file = 'test.h5'
        keys = [
            'results', 'results_hash_dict', 'network_params', 'analysis_params'
        ]

        def _test_func(x):
            return x

        def test_function(network):
            return lmt.utils._cache(network, _test_func, {'x': 1}, 'test')

        empty_network.network_params['a'] = 1
        empty_network.analysis_params['a'] = 1
        test_function(empty_network)

        tmp_test = tmpdir.mkdir('tmp_test')
        with tmp_test.as_cwd():
            io.save_network(file, empty_network, overwrite=True)
            output = h5.load(file)
            for key in keys:
                assert key in output.keys()
            # check that dicts are not empty
            for sub_dict in output.values():
                assert bool(sub_dict)
            # check that all quantities have been converted
            check_dict_contains_no_quantity(output)
 def test_save_overwriting_existing_file_raises_error(
         self, tmpdir, network):
     file = 'test.h5'
     tmp_test = tmpdir.mkdir('tmp_test')
     with tmp_test.as_cwd():
         with pytest.raises(IOError):
             io.save_network(file, network)
             io.save_network(file, network)
Exemplo n.º 3
0
 def test_save_creates_correct_output(self, tmpdir, mocker, network):
     file = 'test.h5'
     keys = ['results', 'results_hash_dict', 'network_params',
             'analysis_params']
     
     @lmt.Network._check_and_store(['test'], ['test_key'])
     def test_method(self, key):
         return 1 * ureg.ms
 
     mocker.patch.object(lmt.Network, 'mean_input', new=test_method)
     network.mean_input(np.array([1, 2, 3]) * ureg.ms)
     
     tmp_test = tmpdir.mkdir('tmp_test')
     with tmp_test.as_cwd():
         io.save_network(file, network)
         output = h5.load(file)
         for key in keys:
             assert key in output.keys()
         # check that dicts are not empty
         for sub_dict in output.values():
             assert bool(sub_dict)
         # check that all quantities have been converted
         check_dict_contains_no_quantity(output)
 def test_h5_is_created(self, tmpdir, network):
     tmp_test = tmpdir.mkdir('tmp_test')
     file = 'test.h5'
     with tmp_test.as_cwd():
         io.save_network(file, network)
     check_file_in_tmpdir(file, tmp_test)