Exemplo n.º 1
0
def test_error_unpickling():
    unpickle_error = RuntimeError("Could not unpickle")
    b64pickled_value = b64encode("pickled value".encode('ascii'))

    with mock.patch(
        'pickle.loads',
        side_effect=unpickle_error,
    ):
        with pytest.raises(b64pickle.PickleLoadsError) as exc_info:
            b64pickle.loads(b64pickled_value)

    assert exc_info.value.args[0] == unpickle_error
    assert exc_info.value.args[1] == "pickled value"
def test_string_stdout_roundtrip():
    obj = 'whatever 🚀'
    output = StringIO()
    with redirect_stdout(output):
        print('--kwargs=%s' % b64pickle.dumps(obj))
    option = output.getvalue()
    key, val = option.split('=', 1)
    print(option)
    print(val)
    assert b64pickle.loads(val) == obj
Exemplo n.º 3
0
def test_string_stdout_roundtrip():
    obj = 'whatever 🚀'
    output = StringIO()
    with redirect_stdout(output):
        print('--kwargs=%s' % b64pickle.dumps(obj))
    option = output.getvalue()
    key, val = option.split('=', 1)
    print(option)
    print(val)
    assert b64pickle.loads(val) == obj
def test_datetime_timezone_utc():
    obj = datetime.now().replace(tzinfo=pytz.UTC)
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
def test_datetime_timezone():
    obj = datetime.now().replace(tzinfo=pytz.timezone('US/Pacific'))
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
def test_decimal():
    obj = Decimal('3.25')
    encoded = b64pickle.dumps(obj)
    # can't know from JSON that it was Decimal
    assert b64pickle.loads(encoded) == obj
def test_list():
    obj = ['whatever 🚀']
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
def test_dict():
    obj = {'val': 'whatever 🚀'}
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 9
0
def test_decimal():
    obj = Decimal('3.25')
    encoded = b64pickle.dumps(obj)
    # can't know from JSON that it was Decimal
    assert b64pickle.loads(encoded) == obj
def test_model_queryset():
    Semaphore.objects.create()
    obj = list(Semaphore.objects.all())
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 11
0
def test_time():
    obj = datetime.now().time()
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 12
0
def test_model_queryset():
    Semaphore.objects.create()
    obj = list(Semaphore.objects.all())
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 13
0
def test_date():
    obj = date.today()
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 14
0
def test_datetime_timezone_utc():
    obj = datetime.now().replace(tzinfo=pytz.UTC)
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 15
0
def test_datetime_timezone():
    obj = datetime.now().replace(tzinfo=pytz.timezone('US/Pacific'))
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
def test_date():
    obj = date.today()
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 17
0
def test_dict():
    obj = {'val': 'whatever 🚀'}
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
def test_time():
    obj = datetime.now().time()
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
def test_string():
    obj = 'whatever 🚀'
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 20
0
def test_string():
    obj = 'whatever 🚀'
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj
Exemplo n.º 21
0
def test_list():
    obj = ['whatever 🚀']
    encoded = b64pickle.dumps(obj)
    assert b64pickle.loads(encoded) == obj