<commit_before>Given /^LIS Interface listening for messages$/ do
  @client, @r, @w = PacketIO::Test::MockServer.build
  @io = PacketIO::IOListener.new(@r, @w)
  @server = LIS::InterfaceServer.create(@io, "http://localhost/lis")

  stub_request(:post, /http:\/\/localhost\/result\/DPC-.*/).
    with(:body => /.*/, :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
    to_return(:status => 200, :body => "", :headers => {})


  @t = Thread.new do
    @server.run!
  end
  @t.abort_on_exception = true
end

When /^receiving data$/ do |string|
  @client.wait(1)
  @client.write("\005")
  string.each_line do |l|
    line, checksum = l.strip.split(/\s*,\s*/)
    checksum = line.each_byte.inject(16) { |a,b| (a+b) % 0x100 }.to_s(16) if checksum.nil?

    @client.write("\002#{line}\015\003#{checksum}\015\012")
  end
  @client.write("\004")
  @client.eof
  @t.join
end

Then /^should have posted results:$/ do |table|
  # table is a Cucumber::Ast::Table
  table.hashes.each do |row|
    expected_body = ["test_name", "value", "unit", "status", "flags", "result_timestamp"].inject({}) { |h,k| h[k] = row[k]; h }
    assert_requested(:post, "http://localhost/result/#{row["id"]}", :times => 1, :body => expected_body)
  end

end

Then /^the server should have acknowledged (\d+) packets$/ do |packet_count|
  @data = @client.read_all
  assert_equal packet_count.to_i, @data.split(//).length
  assert @data.match(/^\006{#{packet_count}}$/), "should contain #{packet_count.to_i} ACKs, was #{@data.inspect}"
end



<commit_msg>post to http://localhost/lis/* in tests<commit_after>Given /^LIS Interface listening for messages$/ do
  @client, @r, @w = PacketIO::Test::MockServer.build
  @io = PacketIO::IOListener.new(@r, @w)
  @server = LIS::InterfaceServer.create(@io, "http://localhost/lis/")

  stub_request(:post, /http:\/\/localhost\/lis\/result\/.*/).
    with(:body => /.*/, :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
    to_return(:status => 200, :body => "", :headers => {})


  @t = Thread.new do
    @server.run!
  end
  @t.abort_on_exception = true
end

When /^receiving data$/ do |string|
  @client.wait(1)
  @client.write("\005")
  string.each_line do |l|
    line, checksum = l.strip.split(/\s*,\s*/)
    checksum = line.each_byte.inject(16) { |a,b| (a+b) % 0x100 }.to_s(16) if checksum.nil?

    @client.write("\002#{line}\015\003#{checksum}\015\012")
  end
  @client.write("\004")
  @client.eof
  @t.join
end

Then /^should have posted results:$/ do |table|
  # table is a Cucumber::Ast::Table
  table.hashes.each do |row|
    expected_body = ["test_name", "value", "unit", "status", "flags", "result_timestamp"].inject({}) { |h,k| h[k] = row[k]; h }
    assert_requested(:post, "http://localhost/lis/result/#{row["id"]}", :times => 1, :body => expected_body)
  end

end

Then /^the server should have acknowledged (\d+) packets$/ do |packet_count|
  @data = @client.read_all
  assert_equal packet_count.to_i, @data.split(//).length
  assert @data.match(/^\006{#{packet_count}}$/), "should contain #{packet_count.to_i} ACKs, was #{@data.inspect}"
end




{'fraction_non_alphanumeric': 0.21715901948460087, 'fraction_numerical': 0.023255813953488372, 'mean_word_length': 3.989028213166144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1442859', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1180, 'n_words': 244}