<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import itertools
import tempfile
from zipfile import ZipFile

from utils.summary_downloader import SummaryDownloader


def test_download_unzipped():

    date = "Oct 24, 2016"
    tgt_dir = tempfile.mkdtemp(prefix='sdl_test_')
    prefixes = ["ES", "FC", "GS", "PL", "RO", "SS", "TH", "TV"]
    game_ids = ["020081", "020082"]

    # setting up list of all HTML report files that should be downloaded for
    # specified date
    files = ["".join(c) + ".HTM" for c in list(
        itertools.product(prefixes, game_ids))]
    # adding JSON game report files
    files.extend(["".join((gid, ".json")) for gid in game_ids])
    # adding shootout report for one of the games
    files.append("SO020082.HTM")

    sdl = SummaryDownloader(tgt_dir, date, zip_summaries=False)
    sdl.run()
    tgt_dir = sdl.get_tgt_dir()

    assert sorted(os.listdir(tgt_dir)) == sorted(files)


def test_download_zipped():

    date = "Oct 24, 2016"
    tgt_dir = tempfile.mkdtemp(prefix='sdl_test_')
    prefixes = ["ES", "FC", "GS", "PL", "RO", "SS", "TH", "TV"]
    game_ids = ["020081", "020082"]

    # setting up list of all HTML report files that should be downloaded for
    # specified date
    files = ["".join(c) + ".HTM" for c in list(
        itertools.product(prefixes, game_ids))]
    # adding JSON game report files
    files.extend(["".join((gid, ".json")) for gid in game_ids])
    # adding shootout report for one of the games
    files.append("SO020082.HTM")

    sdl = SummaryDownloader(tgt_dir, date)
    sdl.run()
    zip_path = sdl.get_zip_path()

    zip = ZipFile(zip_path)

    assert sorted(zip.namelist()) == sorted(files)<commit_msg>Move setup of comparison files to separate method<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import itertools
import tempfile
from zipfile import ZipFile

from utils.summary_downloader import SummaryDownloader


def test_download_unzipped():

    base_tgt_dir, date, files = set_up_comparison_files()

    sdl = SummaryDownloader(base_tgt_dir, date, zip_summaries=False)
    sdl.run()
    tgt_dir = sdl.get_tgt_dir()

    assert sorted(os.listdir(tgt_dir)) == sorted(files)


def test_download_zipped():

    tgt_dir, date, files = set_up_comparison_files()

    sdl = SummaryDownloader(tgt_dir, date)
    sdl.run()
    zip_path = sdl.get_zip_path()

    zip = ZipFile(zip_path)

    assert sorted(zip.namelist()) == sorted(files)


def set_up_comparison_files():

    tgt_dir = tempfile.mkdtemp(prefix='sdl_test_')
    date = "Oct 24, 2016"
    prefixes = ["ES", "FC", "GS", "PL", "RO", "SS", "TH", "TV"]
    game_ids = ["020081", "020082"]

    # setting up list of all HTML report files that should be downloaded for
    # specified date
    files = ["".join(c) + ".HTM" for c in list(
        itertools.product(prefixes, game_ids))]
    # adding JSON game report files
    files.extend(["".join((gid, ".json")) for gid in game_ids])
    # adding shootout report for one of the games
    files.append("SO020082.HTM")

    return tgt_dir, date, files
{'fraction_non_alphanumeric': 0.13574660633484162, 'fraction_numerical': 0.023917259211376857, 'mean_word_length': 3.591988130563798, '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': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4130487', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1047, 'n_words': 292}