<commit_before>#!/usr/bin/python
#
# Copyright 2014 Google Inc.
#
# 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.
#
################################################################################
#
# Tests handling of VM images (e.g., shortnames).

import json
import os
import unittest

# Local imports
import config


class ConfigExpanderTest(unittest.TestCase):

  def _FileBasename(self, filename):
    base1 = os.path.splitext(filename)[0]
    return os.path.splitext(base1)[0]

  def testFileBasename(self):
    before_after = (
        ('abc.in.yaml', 'abc'),
        ('foo.out.json', 'foo'),
    )
    for before, after in before_after:
      self.assertEqual(after, self._FileBasename(before))

  def testAllFiles(self):
    all_files = os.listdir(os.path.join(os.path.dirname(__file__), 'testdata'))
    unique_files = sorted(set(map(lambda x: self._FileBasename(x), all_files)))
    for filename in unique_files:
      expected = 'testdata/%s.out.json' % filename
      with open(expected) as expected_in:
        expected_json = json.loads(expected_in.read(), encoding='utf-8')

      input_file = 'testdata/%s.in.yaml' % filename
      expander = config.ConfigExpander(project='dummy-project', zone='dummy-zone')
      actual_json = expander.ExpandFile(input_file)
<commit_msg>Simplify test case discovery via glob() instead of listdir() + custom code.<commit_after>#!/usr/bin/python
#
# Copyright 2014 Google Inc.
#
# 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.
#
################################################################################
#
# Tests handling of VM images (e.g., shortnames).

import glob
import json
import os
import unittest

# Local imports
import config


class ConfigExpanderTest(unittest.TestCase):

  def testAllFiles(self):
    in_yaml = glob.glob(os.path.join('testdata', '*.in.yaml'))
    for input_file in in_yaml:
      expected = input_file.replace('in.yaml', 'out.json')
      with open(expected) as expected_in:
        expected_json = json.loads(expected_in.read(), encoding='utf-8')

      expander = config.ConfigExpander(project='dummy-project', zone='dummy-zone')
      actual_json = expander.ExpandFile(input_file)

{'fraction_non_alphanumeric': 0.15214646464646464, 'fraction_numerical': 0.006944444444444444, 'mean_word_length': 4.281666666666666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2318062', 'n_tokens_mistral': 903, 'n_tokens_neox': 876, 'n_words': 293}