<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests the local filesystem collector."""

from __future__ import unicode_literals

import os
import unittest

import six

from dftimewolf.lib.recipes import manager as recipes_manager


class RecipeTests(unittest.TestCase):
  """Tests for recipe construction."""

  def setUp(self):
    recipes_path = os.path.dirname(__file__)
    recipes_path = os.path.dirname(recipes_path)
    recipes_path = os.path.join(recipes_path, 'data', 'recipes')

    self._recipes_manager = recipes_manager.RecipesManager()
    self._recipes_manager.ReadRecipesFromDirectory(recipes_path)

  def testRecipeHasFields(self):
    """Tests that all recipes have the correct fields."""
    for recipe in self._recipes_manager.GetRecipes():
      self.assertIsNotNone(recipe.name)
      self.assertIsNotNone(recipe.description)
      self.assertIn('modules', recipe.contents)
      self.assertIsInstance(recipe.contents['modules'], list)

      self.assertIsInstance(recipe.args, list)

  def testRecipeModulesHaveFields(self):
    """Tests that modules defined in the recipe have the correct fields."""
    for recipe in self._recipes_manager.GetRecipes():
      for module in recipe.contents['modules']:
        error_msg = 'module {0:s} in recipe {1:s}'.format(
            module['name'], recipe.contents['name'])

        self.assertIn('wants', module, msg=error_msg)
        self.assertIn('name', module, msg=error_msg)
        self.assertIn('args', module, msg=error_msg)

        self.assertIsInstance(module['wants'], list, msg=error_msg)
        self.assertIsInstance(module['args'], dict, msg=error_msg)
        self.assertIsInstance(module['name'], six.string_types, msg=error_msg)

  def testRecipeModulesAllPresent(self):
    """Tests that a recipe's modules depend only on modules present in the
    recipe."""<commit_msg>Load recipes from correct directory (#207)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests the local filesystem collector."""

from __future__ import unicode_literals

import os
import unittest

import six

from dftimewolf.lib.recipes import manager as recipes_manager


class RecipeTests(unittest.TestCase):
  """Tests for recipe construction."""

  def setUp(self):
    recipes_path = os.path.dirname(__file__)
    recipes_path = os.path.dirname(recipes_path)
    recipes_path = os.path.dirname(recipes_path)
    recipes_path = os.path.join(recipes_path, 'data', 'recipes')

    self._recipes_manager = recipes_manager.RecipesManager()
    self._recipes_manager.ReadRecipesFromDirectory(recipes_path)

  def tearDown(self):
    for recipe in self._recipes_manager.GetRecipes():
      self._recipes_manager.DeregisterRecipe(recipe)

  def testRecipeHasFields(self):
    """Tests that all recipes have the correct fields."""
    for recipe in self._recipes_manager.GetRecipes():
      self.assertIsNotNone(recipe.name)
      self.assertIsNotNone(recipe.description)
      self.assertIn('modules', recipe.contents)
      self.assertIsInstance(recipe.contents['modules'], list)

      self.assertIsInstance(recipe.args, list)

  def testRecipeModulesHaveFields(self):
    """Tests that modules defined in the recipe have the correct fields."""
    for recipe in self._recipes_manager.GetRecipes():
      for module in recipe.contents['modules']:
        error_msg = 'module {0:s} in recipe {1:s}'.format(
            module['name'], recipe.contents['name'])

        self.assertIn('wants', module, msg=error_msg)
        self.assertIn('name', module, msg=error_msg)
        self.assertIn('args', module, msg=error_msg)

        self.assertIsInstance(module['wants'], list, msg=error_msg)
        self.assertIsInstance(module['args'], dict, msg=error_msg)
        self.assertIsInstance(module['name'], six.string_types, msg=error_msg)

  def testRecipeModulesAllPresent(self):
    """Tests that a recipe's modules depend only on modules present in the
    recipe."""
{'fraction_non_alphanumeric': 0.11773623041940375, 'fraction_numerical': 0.0022738756947953513, 'mean_word_length': 4.257636122177955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6572359', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1165, 'n_words': 269}