Esempio n. 1
0
 def test_get_processed_folder_will_not_work_without_arguments(self):
     with pytest.raises(TypeError):
         PathHelper.get_processed_folder()
Esempio n. 2
0
 def test_get_processed_folder_returns_existing_folder(self):
     assert PathHelper.get_processed_folder(2017, 5).exists() is True
Esempio n. 3
0
 def test_locate_csv_on_year_month_path_esists(self):
     assert PathHelper.locate_csv(2017, 5).exists() is True
Esempio n. 4
0
def test_csv_has_no_null_byte():
    csv_path = PathHelper.locate_csv(2015, 2)
    z = csv_path.read_text(encoding='utf-8')
    assert "\0" not in z
Esempio n. 5
0
    'label': 'GDP_bln_rub',
    'period': 4,
    'value': 2044,
    'year': 2000
}]
checker = Validator(dfa, dfq, dfm)
for c in check_points:
    assert checker.is_included(c)

# Example 3 Read actual data by month and year
year, month = 2017, 5

# 3.1 Access to csv file using path helper
from config import PathHelper
from csv2df.specification import SPEC
csv_path = PathHelper.locate_csv(year, month)
with open_csv(csv_path) as csvfile:
    dfa1, dfq1, dfm1 = get_dataframes(csvfile, SPEC)

# 3.2 Access to csv file using Vintage class (identical to 3.1)
from csv2df.runner import Vintage
vint = Vintage(year, month)
dfa2, dfq2, dfm2 = vint.dfs()

assert dfa1.equals(dfa2)
assert dfq1.equals(dfq2)
assert dfm1.equals(dfm2)

# validation
assert vint.validate()
Esempio n. 6
0
# -*- coding: utf-8 -*-
"""Download and unpack Word files from Rosstat web site."""

import os
import subprocess
import requests
import datetime

from config import PathHelper

UNPACK_RAR_EXE = PathHelper.get_unrar_binary()


def download(url, path):
    r = requests.get(url.strip(), stream=True)
    with open(path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:  # filter out keep-alive new chunks
                f.write(chunk)


def _mask_with_end_separator(folder):
    """UnRAR wants its folder parameter to send with /
       This function supllies a valid folder argument for UnRAR."""
    return "{}{}".format(folder, os.sep)


def unrar(path, folder, unrar=UNPACK_RAR_EXE):
    folder = _mask_with_end_separator(folder)
    assert folder.endswith("/") or folder.endswith("\\")
    tokens = [unrar, 'e', path, folder, '-y']