def load_cassette(cassette_path, serializer): try: with open(cassette_path) as f: cassette_content = f.read() except IOError: return [], [] return deserialize(cassette_content, serializer)
def load_cassette(cassette_path: str, serializer: ModuleType) -> Tuple[List, List]: try: with open(cassette_path) as f: cassette_content = f.read() except OSError: return [], [] return deserialize(cassette_content, serializer)
def load_cassette(cls, cassette_path, serializer): try: with open(cassette_path) as f: cassette_content = f.read() except OSError: raise ValueError("Cassette not found.") for replacement, value in [(v, f"<{k.upper()}>") for k, v in placeholders.items()]: cassette_content = cassette_content.replace(value, replacement) cassette = deserialize(cassette_content, serializer) return cassette
def load_cassette(cls, cassette_path, serializer): """Load the cassette.""" try: with open(cassette_path) as f: cassette_content = f.read() except OSError: raise ValueError("Cassette not found.") for replacement, value in placeholders: cassette_content = cassette_content.replace(value, replacement) cassette = deserialize(cassette_content, serializer) return cassette
def test_deserialize_old_json_cassette(): with open('tests/fixtures/migration/old_cassette.json', 'r') as f: with pytest.raises(ValueError): deserialize(f.read(), jsonserializer)
def test_deserialize_new_json_cassette(): with open('tests/fixtures/migration/new_cassette.json', 'r') as f: deserialize(f.read(), jsonserializer)
def test_deserialize_new_yaml_cassette(): with open('tests/fixtures/migration/new_cassette.yaml', 'r') as f: deserialize(f.read(), yamlserializer)
def test_deserialize_old_yaml_cassette(): with open("tests/fixtures/migration/old_cassette.yaml", "r") as f: with pytest.raises(ValueError): deserialize(f.read(), yamlserializer)
def test_deserialize_py2py3_yaml_cassette(tmpdir, req_body, expect): cfile = tmpdir.join("test_cassette.yaml") cfile.write(REQBODY_TEMPLATE.format(req_body=req_body)) with open(str(cfile)) as f: (requests, responses) = deserialize(f.read(), yamlserializer) assert requests[0].body == expect
def test_deserialize_new_json_cassette(): with open("tests/fixtures/migration/new_cassette.json", "r") as f: deserialize(f.read(), jsonserializer)
def test_deserialize_new_yaml_cassette(): with open("tests/fixtures/migration/new_cassette.yaml", "r") as f: deserialize(f.read(), yamlserializer)
def test_deserialize_py2py3_yaml_cassette(tmpdir, req_body, expect): cfile = tmpdir.join('test_cassette.yaml') cfile.write(REQBODY_TEMPLATE.format(req_body=req_body)) with open(str(cfile)) as f: (requests, responses) = deserialize(f.read(), yamlserializer) assert requests[0].body == expect
def _extract_vcr_object(file_path): with open(file_path, "rb") as cassette: return VcrObject(file_path, deserialize(cassette.read(), yamlserializer))