<commit_before>require 'test_helper'
require 'tempfile'
require 'tmpdir'
require 'erb'
require 'json'

class TestHelpers < Test::Unit::TestCase
  def setup
    @data_dir = Dir.mktmpdir
    @taskrc_file = build_taskrc(:data_dir => @data_dir)
  end
  
  def teardown
    FileUtils.rm_r(@data_dir)
    File.delete(@taskrc_file)
  end

  def test_empty
    # http://taskwarrior.org/issues/1017
    # assert_empty(export_tasks)
    
    # Use a placeholder as workaround
    exec("add placeholder")
    assert_equal(1, export_tasks.size)
  end
  
  def test_import
    contents = {:description => "foobar"}
    input_file = Tempfile.new('test_simple')
    
    begin
      input_file.write(contents.to_json)
      input_file.close
      exec("import #{input_file.path}")
      
      tasks = export_tasks
      assert_equal(1, tasks.size)
      assert_equal('foobar', tasks.first['description'])<commit_msg>Add comment about removing temp file<commit_after>require 'test_helper'
require 'tempfile'
require 'tmpdir'
require 'erb'
require 'json'

class TestHelpers < Test::Unit::TestCase
  def setup
    @data_dir = Dir.mktmpdir
    @taskrc_file = build_taskrc(:data_dir => @data_dir)
  end
  
  def teardown
    FileUtils.rm_r(@data_dir)
    File.delete(@taskrc_file)
  end

  def test_empty
    # http://taskwarrior.org/issues/1017
    # assert_empty(export_tasks)
    
    # Use a placeholder as workaround
    exec("add placeholder")
    assert_equal(1, export_tasks.size)
  end
  
  def test_import
    contents = {:description => "foobar"}
    input_file = Tempfile.new('test_simple')
    
    begin
      input_file.write(contents.to_json)
      input_file.close
      
      # TODO Replace temp file with in-process version
#      exec("import <(echo '#{contents.to_json}')")
      exec("import #{input_file.path}")
      
      tasks = export_tasks
      assert_equal(1, tasks.size)
      assert_equal('foobar', tasks.first['description'])
{'fraction_non_alphanumeric': 0.10922205048943844, 'fraction_numerical': 0.0061823802163833074, 'mean_word_length': 3.2964601769911503, 'pattern_counts': {'":': 0, '<': 6, '<?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': '4520252', 'n_tokens_mistral': 652, 'n_tokens_neox': 640, 'n_words': 130}