def test_fsl_abspath(): # fsl_abspath just calls os.path.realpath with tempdir() as td: oneup = op.dirname(td) # (input, expected) tests = [ ('file', f'{td}/file'), ('./file', f'{td}/file'), ('../file', f'{oneup}/file'), ('/file', '/file'), ('/one/two/file', '/one/two/file'), ] for input, expected in tests: cap = CaptureStdout() with cap: ret = fsl_abspath.main([input]) assert ret == 0 assert cap.stdout.strip() == expected
def test_cli_generate_account_and_account_info(): with tempdir() as tmp_path: account_path = os.path.join(tmp_path, 'key') j = call_aecli('account', 'create', account_path, '--password', 'secret') gen_address = j.get("Address") assert utils.is_valid_hash(gen_address, prefix='ak') j1 = call_aecli('account', 'address', account_path, '--password', 'secret') assert utils.is_valid_hash(j1.get('Address'), prefix='ak')
def test_signing_keystore_save_load_wrong_pwd(): with tempdir() as tmp_path: filename = ACCOUNT.save_to_keystore(tmp_path, "whatever") path = os.path.join(tmp_path, filename) print(f"\nAccount keystore is {path}") # now load again the same with raises(ValueError): a = Account.load_from_keystore(path, "nononon") assert a.get_address() == ACCOUNT.get_address()
def test_signing_keystore_save_load(): with tempdir() as tmp_path: filename = ACCOUNT.save_to_keystore(tmp_path, "whatever") path = os.path.join(tmp_path, filename) print(f"\nAccount keystore is {path}") # now load again the same a = Account.load_from_keystore(path, "whatever") assert a.get_address() == ACCOUNT.get_address() with tempdir() as tmp_path: filename = "account_ks" filename = ACCOUNT.save_to_keystore(tmp_path, "whatever", filename=filename) path = os.path.join(tmp_path, filename) print(f"\nAccount keystore is {path}") # now load again the same a = Account.load_from_keystore(path, "whatever") assert a.get_address() == ACCOUNT.get_address()
def test_cli_read_account_fail(): with tempdir() as tmp_path: account_path = os.path.join(tmp_path, 'key') j = call_aecli('account', 'create', account_path, '--password', 'secret') try: j1 = call_aecli('account', 'address', account_path, '--password', 'WRONGPASS') assert j.get("Address") != j1.get("Address") except CalledProcessError: # this is fine because invalid passwords exists the command with retcode 1 pass
def test_cli_generate_account(): with tempdir() as tmp_path: account_key = os.path.join(tmp_path, 'key') j = call_aecli('account', 'create', account_key, '--password', 'secret', '--overwrite') gen_address = j.get("Address") assert utils.is_valid_hash(gen_address, prefix='ak') # make sure the folder contains the keys files = sorted(os.listdir(tmp_path)) assert len(files) == 1 assert files[0].startswith("key")
def test_Text2Vest(): with tempdir(): data = np.random.random((20, 10)) np.savetxt('data.txt', data) assert Text2Vest.main(['data.txt', 'data.vest']) == 0 got = fslvest.loadVestFile('data.vest', ignoreHeader=False) assert np.all(np.isclose(data, got))
def test_Vest2Text(): with tempdir(): data = np.random.random((20, 10)) vest = fslvest.generateVest(data) with open('data.vest', 'wt') as f: f.write(vest) assert Vest2Text.main(['data.vest', 'data.txt']) == 0 got = np.loadtxt('data.txt') assert np.all(np.isclose(data, got))
def test_loadVestFile(): def genvest(data, path, shapeOverride=None): if shapeOverride is None: nrows, ncols = data.shape else: nrows, ncols = shapeOverride with open(path, 'wt') as f: f.write(f'/NumWaves {ncols}\n') f.write(f'/NumPoints {nrows}\n') f.write( '/Matrix\n') if np.issubdtype(data.dtype, np.integer): fmt = '%d' else: fmt = '%0.12f' np.savetxt(f, data, fmt=fmt) with tempdir(): data = np.random.randint(1, 100, (10, 20)) genvest(data, 'data.vest') assert np.all(data == vest.loadVestFile('data.vest')) data = np.random.random((20, 10)) genvest(data, 'data.vest') assert np.all(np.isclose(data, vest.loadVestFile('data.vest'))) # should pass vest.loadVestFile('data.vest', ignoreHeader=False) # invalid VEST header genvest(data, 'data.vest', (10, 20)) # default behaviour - ignore header assert np.all(np.isclose(data, vest.loadVestFile('data.vest'))) with pytest.raises(ValueError): vest.loadVestFile('data.vest', ignoreHeader=False)
def account_path(): with tempdir() as tmp_path: # save the private key on file sender_path = os.path.join(tmp_path, 'sender') ACCOUNT.save_to_keystore_file(sender_path, 'aeternity_bc') yield sender_path