Commit efea0db2 authored by valentin.emiya's avatar valentin.emiya
Browse files

test config file

parent 42def95d
Pipeline #5121 canceled with stage
in 1 minute and 34 seconds
import unittest
from unittest.mock import patch
import tempfile
from pathlib import Path
from configparser import ConfigParser
from tffpy.utils import generate_config, get_data_path
class TestGenerateConfig(unittest.TestCase):
def test_generate_config(self):
with patch('tffpy.utils.get_config_file') as mock:
mock.return_value = Path(tempfile.mkdtemp()) / 'tffpy.conf'
config_file = mock.return_value
self.assertFalse(config_file.exists())
generate_config()
self.assertTrue(config_file.exists())
class TestGetDataPath(unittest.TestCase):
def test_get_data_path(self):
with patch('tffpy.utils.get_config_file') as mock:
mock.return_value = Path(tempfile.mkdtemp()) / 'tffpy.conf'
config_file = mock.return_value
self.assertFalse(config_file.exists())
with self.assertRaises(Exception):
get_data_path()
generate_config()
with self.assertRaises(Exception):
get_data_path()
config = ConfigParser()
config.read(config_file)
true_data_path = Path(__file__).absolute().parents[3] / 'data'
print(true_data_path)
self.assertTrue(true_data_path.exists())
print('Data path:', str(true_data_path))
config.set('DATA', 'data_path', str(true_data_path))
config.write(open(config_file, 'w'))
tested_data_path = get_data_path()
self.assertEqual(tested_data_path, true_data_path)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment