Closed epogrebnyak closed 8 years ago
Must finish tests with following to guarantee the database is filled with most recent data:
from kep.importer.parser.csv2db import import_csv
from kep.paths import CURRENT_MONTH_DATA_FOLDER
import_csv(CURRENT_MONTH_DATA_FOLDER)
is this possible?
Data may be destroyed by some tests. Alternative: use different sqlite file as database in tests, this also should save some time.
@epogrebnyak I totally agree that using a separate test database is a good idea. I'll implement it.
Please tell what is your design idea for that first
@epogrebnyak
1) Change few occurrences where DB_FILE
is used like this:
import kep.paths
...
def get_unique_labels(db_file=None):
if db_file is None:
db_file = kep.paths.DB_FILE
con = sqlite3.connect(db_file)
...
2) Patch kep.paths.DB_FILE
in the beginning of pytest session, using session fixture
This is not the most nice solution, but it's simple and quite safe.
There is much more occurenxirs than 'few". One has to pass it to functions like to_database() and many others.
For code above consider a function get_dbfile(), based on a global flag USE_PRODUCTION_DB_FILE = True, override this flag in testing, if possible. It breaks a bit a rule of passing args to function explicitly, but many functions will preserve clean interfaces then.
пн, 21 дек. 2015, 20:15, Alexander Lukanin notifications@github.com:
@epogrebnyak https://github.com/epogrebnyak 1) Change few occurrences where DB_FILE is used like this:
import kep.paths ... def get_unique_labels(db_file=None): if db_file is None: db_file = kep.paths.DB_FILE con = sqlite3.connect(db_file) ...
2) Patch kep.paths.DB_FILE in the beginning of pytest session, using session fixture http://stackoverflow.com/a/20057171
This is not the most nice solution, but it's simple and quite safe.
— Reply to this email directly or view it on GitHub https://github.com/epogrebnyak/rosstat-kep-data/issues/68#issuecomment-166363315 .
@epogrebnyak No, only a few occurrences because we override global settings in kep.paths
. In fact, I already have a working prototype. Believe me, it's the simplest and cleanest thing we can do: no API changes at all.
Ok then, pull it for me to familiarize with
пн, 21 дек. 2015, 20:38, Alexander Lukanin notifications@github.com:
@epogrebnyak https://github.com/epogrebnyak No, only a few occurrences because we override global settings in kep.paths. In fact, I already have a working prototype. Believe me, it's the simplest and cleanest thing we can do: no API changes at all.
— Reply to this email directly or view it on GitHub https://github.com/epogrebnyak/rosstat-kep-data/issues/68#issuecomment-166369342 .
Also referenced in #20
Note: may also change DATA_FOLDER constant in tests to CURRENT_MONTH_DATA_FOLDER.