Sha256: 1dfa20d9b14c9298c7f22d81140062881cd294160f0c6210889ea95dc9f8b952

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'
require 'python/pickle/protocol1'

require 'protocol0_read_instruction_examples'
require 'protocol1_read_instruction_examples'

describe Python::Pickle::Protocol1 do
  let(:pickle) { '' }
  let(:io) { StringIO.new(pickle) }

  subject { described_class.new(io) }

  describe "#read_float64_be" do
    let(:float)  { 1234.5678 }
    let(:packed) { [float].pack('G') }

    let(:io) { StringIO.new(packed) }

    it "must read eight bytes and decode a big-endian floating point number" do
      expect(subject.read_float64_be).to eq(float)
    end
  end

  describe "#read_uint8" do
    let(:io) { StringIO.new("\xff".b) }

    it "must read a single unsignd byte" do
      expect(subject.read_uint8).to eq(0xff)
    end
  end

  describe "#read_uint32_le" do
    let(:uint32) { 0xffeeddcc }
    let(:packed) { [uint32].pack('L<') }
    let(:io)     { StringIO.new(packed) }

    it "must read four bytes and return an unpacked uint32 in little-endian byte-order" do
      expect(subject.read_uint32_le).to eq(uint32)
    end
  end

  let(:fixtures_dir) { File.join(__dir__,'fixtures') }

  describe "#read_instruction" do
    include_context "Protocol0#read_instruction examples"
    include_context "Protocol1#read_instruction examples"

    context "when the opcode is not recognized" do
      let(:opcode) { 255 }
      let(:io)     { StringIO.new(opcode.chr) }

      it do
        expect {
          subject.read_instruction
        }.to raise_error(Python::Pickle::InvalidFormat,"invalid opcode (#{opcode.inspect}) for protocol 1")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
python-pickle-0.2.0 spec/protocol1_spec.rb
python-pickle-0.1.1 spec/protocol1_spec.rb
python-pickle-0.1.0 spec/protocol1_spec.rb