<commit_before>from keras_autodoc.autogen import generate
from docs.autogen import keras_dir, clean_module_name
from docs.structure import PAGES, EXCLUDE
import shutil
import os

from pathlib import Path

def make_keras_docs(dest_dir):
    dest_dir = Path(dest_dir)
    template_dir = keras_dir / 'docs' / 'templates'
    generate(dest_dir,
             template_dir,
             PAGES,
             keras_dir / 'examples',
             EXCLUDE,
             clean_module_name=clean_module_name)
    readme = (keras_dir / 'README.md').read_text()
    index = (template_dir / 'index.md').read_text()
    index = index.replace('{{autogenerated}}', readme[readme.find('##'):])
    (dest_dir / 'index.md').write_text(index, encoding='utf-8')
    shutil.copyfile(keras_dir / 'CONTRIBUTING.md', dest_dir / 'contributing.md')


def test_docs_in_custom_destination_dir(tmpdir):
    make_keras_docs(tmpdir)
    tmpdir = Path(tmpdir)
    assert (tmpdir / 'layers').is_dir()
    assert (tmpdir / 'models').is_dir()
    assert (tmpdir / 'examples').is_dir()
    assert 'for easy and fast' in (tmpdir / 'index.md').read_text()
    assert os.listdir(tmpdir / 'examples')
    for file_path in get_all_files(tmpdir):
        text = file_path.read_text()
        assert 'keras_applications' not in text
        assert 'keras_preprocessing' not in text
        assert 'keras.layer.core' not in text
        assert 'layer.pooling' not in text
        assert 'utils.np_utils' not in text
        assert 'backend.tensorflow_backend' not in text


def get_all_files(directory):
    for root, dirs, files in os.walk(directory):
        root = Path(root)
        for f in files:
            yield root / f<commit_msg>Fixed a test.<commit_after>from keras_autodoc.autogen import generate
from docs.autogen import keras_dir, clean_module_name, post_process_signature
from docs.structure import PAGES, EXCLUDE
import shutil
import os

from pathlib import Path


def make_keras_docs(dest_dir):
    dest_dir = Path(dest_dir)
    template_dir = keras_dir / 'docs' / 'templates'
    generate(dest_dir,
             template_dir,
             PAGES,
             keras_dir / 'examples',
             EXCLUDE,
             clean_module_name=clean_module_name,
             post_process_signature=post_process_signature)
    readme = (keras_dir / 'README.md').read_text()
    index = (template_dir / 'index.md').read_text()
    index = index.replace('{{autogenerated}}', readme[readme.find('##'):])
    (dest_dir / 'index.md').write_text(index, encoding='utf-8')
    shutil.copyfile(keras_dir / 'CONTRIBUTING.md', dest_dir / 'contributing.md')


def test_docs_in_custom_destination_dir(tmpdir):
    make_keras_docs(tmpdir)
    tmpdir = Path(tmpdir)
    assert (tmpdir / 'layers').is_dir()
    assert (tmpdir / 'models').is_dir()
    assert (tmpdir / 'examples').is_dir()
    assert 'for easy and fast' in (tmpdir / 'index.md').read_text()
    assert os.listdir(tmpdir / 'examples')
    text = []
    for file_path in get_all_files(tmpdir):
        text.append(file_path.read_text())
    text = '\n'.join(text)
    assert 'keras_applications' not in text
    assert 'keras_preprocessing' not in text
    assert 'keras.layers.core' not in text
    assert 'layers.pooling' not in text
    assert 'utils.np_utils' not in text
    assert 'backend.tensorflow_backend' not in text

    assert 'keras.layers.Dense' in text


def get_all_files(directory):
    for root, dirs, files in os.walk(directory):
        root = Path(root)
        for f in files:
            yield root / f
{'fraction_non_alphanumeric': 0.11076575303758124, 'fraction_numerical': 0.0005651313930488839, 'mean_word_length': 3.135514018691589, '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': '6489252', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1148, 'n_words': 271}