<commit_before>require 'spec_helper'
require 'open-uri'
describe "Descartes", :js => true do

	type = "Descartes"
	name = "wave:sine"
	descartes_host = ENV["TEST_DESCARTES_HOST"]
	raise StandardError, "Missing environment variable ENV['TEST_DESCARTES_HOST']" unless descartes_host
	origin = ENV["TEST_DESCARTES_ORIGIN"]
	raise StandardError, "Missing environment variable ENV['TEST_DESCARTES_ORIGIN']" unless origin
	metric = "#{type}~#{name}" 

	begin
                URI.parse(descartes_host).read
        rescue Errno::ECONNREFUSED,Errno::EHOSTUNREACH => e
                raise StandardError, "\n\nYou can't test the Descartes endpoint at #{descartes_host} unless it's live, dummy. \n\n#{e}\n\n"
        end

	before :each do 
		add_config "backends: [{ type: '#{type}', settings: {url: '#{descartes_host}', origin: '#{origin}'}}]\nautoplay: false "
		test_config type
	end

        context "refresh metrics" do
                include_examples "refresh metrics", type
        end<commit_msg>Update descartes local test to use a source as listed in the origin list, for dynamic-ness<commit_after>require 'spec_helper'
require 'open-uri'
describe "Descartes", :js => true do

	descartes_host = ENV["TEST_DESCARTES_HOST"]
	raise StandardError, "Missing environment variable ENV['TEST_DESCARTES_HOST']" unless descartes_host
	origin = ENV["TEST_DESCARTES_ORIGIN"]
	raise StandardError, "Missing environment variable ENV['TEST_DESCARTES_ORIGIN']" unless origin

	begin
                URI.parse(descartes_host).read
        rescue Errno::ECONNREFUSED,Errno::EHOSTUNREACH => e
                raise StandardError, "\n\nYou can't test the Descartes endpoint at #{descartes_host} unless it's live, dummy. \n\n#{e}\n\n"
        end

	# Since origin is dynamic, should just use one of the sources we can
	# see, as opposed to hard coding it here
	source = URI.parse(descartes_host+"/simple/search?&origin=#{origin}")	
	name = JSON.parse(source.read).first.gsub("~", ":")
	type = "Descartes"
	metric = "#{type}~#{name}" 

	before :each do 
		add_config "backends: [{ type: '#{type}', settings: {url: '#{descartes_host}', origin: '#{origin}'}}]\nautoplay: false "
		test_config type
	end

        context "refresh metrics" do
                include_examples "refresh metrics", type
        end
{'fraction_non_alphanumeric': 0.1219938784433756, 'fraction_numerical': 0.0, 'mean_word_length': 4.017543859649122, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1527089', 'n_tokens_mistral': 758, 'n_tokens_neox': 733, 'n_words': 199}