<commit_before># Copyright 2014 <NAME>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Common helpers for testing the courier
shared_context 'Helpers_Log_Courier' do
  before :each do
    @config = File.open(File.join(TEMP_PATH, 'config'), 'w')

    @log_courier = nil
  end

  after :each do
    shutdown

    File.unlink(@config.path) if File.file?(@config.path)

    # This is important or the state will not be clean for the following test
    File.unlink('.log-courier') if File.file?('.log-courier')
  end

  def startup(config: nil, args: '', mode: 'r')
    # A standard configuration when we don't want anything special
    if config.nil?
      config = <<-config<commit_msg>Fix a previous interrupted test causing next test failure<commit_after># Copyright 2014 <NAME>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Common helpers for testing the courier
shared_context 'Helpers_Log_Courier' do
  before :all do
    # Just in case of a remnant from a previous run that did not cleanup
    File.unlink('.log-courier') if File.file?('.log-courier')
  end

  before :each do
    @config = File.open(File.join(TEMP_PATH, 'config'), 'w')

    @log_courier = nil
  end

  after :each do
    shutdown

    File.unlink(@config.path) if File.file?(@config.path)

    # This is important or the state will not be clean for the following test
    File.unlink('.log-courier') if File.file?('.log-courier')
  end

  def startup(config: nil, args: '', mode: 'r')
    # A standard configuration when we don't want anything special
    if config.nil?
      config = <<-config
{'fraction_non_alphanumeric': 0.09239766081871345, 'fraction_numerical': 0.006237816764132553, 'mean_word_length': 3.7695167286245352, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '2467341', 'n_tokens_mistral': 738, 'n_tokens_neox': 715, 'n_words': 318}