-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
86 lines (61 loc) · 2.26 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unit Tests
----------
This module performs unit tests for each helper scripts.
"""
import unittest
import os
from environment_helper import Environment
__author__ = "Lucas Hohmann"
__email__ = "lfhohmann@gmail.com"
__user__ = "@lfhohmann"
__status__ = "Production"
__date__ = "2022/04/16"
__version__ = "2.0.0"
__license__ = "MIT"
class TestEnvironmentHelper(unittest.TestCase):
"""
Environment Helper Test
-----------------------
Tests the Environment Helper variables class
#### Note:
Only the current environment mode ("kaggle" or "local") will be tested
"""
# Check current environment mode
current_mode = "kaggle" if "kaggle" in os.getcwd() else "local"
def test_mode(self) -> None:
"""Test if the current environment mode is "kaggle" or "local"."""
# Instantiate the environment variables class
env = Environment()
# Check if the current environment is "kaggle" or "local"
self.assertEqual(env.mode, self.current_mode)
def test_readonly_attributes(self) -> None:
"""Test if the readonly attributes ("mode", "path_input", "path_output") can't be set"""
# Instantiate the environment variables class
env = Environment()
# Check if the readonly attributes can't be set
for attribute in ["mode", "path_input", "path_output"]:
with self.assertRaises(AttributeError):
setattr(env, attribute, "value")
def test_variables(self) -> None:
"""Test if the custom variables are set correctly"""
data = {
"kaggle": {
"train_path": "/kaggle/train.csv",
"test_path": "/kaggle/test.csv",
},
"local": {
"train_path": "/local/train.csv",
"test_path": "/local/test.csv",
},
}
# Instantiate the environment variables class with custom data
env = Environment(data)
# Check if the custom variables are set correctly
for attribute in data[env.mode].keys():
value = data[self.current_mode][attribute]
self.assertEqual(value, getattr(env, attribute))
if __name__ == "__main__":
unittest.main(verbosity=2)