def test_shelf_in(writer, filename, password): with file_cleanup(test_file): shelf = pc.EncryptedShelf(writer, filename, password) shelf["key"] = "value" assert "key" in shelf assert "notkey" not in shelf shelf.close()
def test_tell(method): test_data = "some even more different test data" with file_cleanup(test_file): file = method(open(test_file, 'w'), test_pass) assert file.tell() == 0 file.write(test_data) assert file.tell() == len(test_data) file.close()
def test_shelf_get(writer, filename, password): with file_cleanup(test_file): shelf = pc.EncryptedShelf(writer, filename, password) shelf["key"] = "value" assert shelf["key"] == "value" assert shelf.get("key") == "value" assert shelf.get("notkey") is None assert shelf.get("notkey", "notvalue") == "notvalue" shelf.close()
def test_read(method): test_data = "Some more test data" with file_cleanup(test_file): file = method(open(test_file, 'w'), test_pass) file.write(test_data) file.close() file = method(test_file, test_pass) assert test_data == file.read() file.close()
def test_seek(method): test_data = "1234567890" with file_cleanup(test_file): file = method(open(test_file, 'w'), test_pass) file.write(test_data) file.close() file = method(test_file, test_pass) file.seek(-2, 2) assert file.read() == test_data[-2:] file.close()
def test_shelf_save(writer, filename, password): with file_cleanup(test_file): shelf = pc.EncryptedShelf(writer, filename, password) shelf["somekey"] = "somevalue" shelf.close() shelf = None # load up the old shelf shelf = pc.EncryptedShelf(writer, filename, password) assert shelf["somekey"] == "somevalue" shelf.close()
def test_write(method): with file_cleanup(test_file): file = method(open(test_file, 'w'), test_pass) file.write("some test data") file.close()
def test_shelf_set(writer, filename, password): with file_cleanup(test_file): shelf = pc.EncryptedShelf(writer, filename, password) shelf["key"] = "value" assert shelf["key"] == "value" shelf.close()
def test_shelf_create(writer, filename, password): with file_cleanup(test_file): shelf = pc.EncryptedShelf(writer, filename, password) shelf.close()
def test_constructors(method): "Test the various file's constructors" with file_cleanup(test_file): file = method(open(test_file, 'w'), test_pass) file.close()