-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_file_storage.py
executable file
·79 lines (63 loc) · 2.38 KB
/
test_file_storage.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
#!/usr/bin/python3
"""
Unittest FileStorage class
"""
import unittest
import pep8
import os
from models import base_model
from models.base_model import BaseModel
from models.engine import file_storage
from models.engine.file_storage import FileStorage
class TestPep8B(unittest.TestCase):
""" Test pep8 style validation """
def test_pep8(self):
""" test base and test_base for pep8 conformance """
style = pep8.StyleGuide(quiet=True)
file1 = 'models/engine/file_storage.py'
file2 = 'tests/test_models/test_engine/test_file_storage.py'
result = style.check_files([file1, file2])
self.assertEqual(result.total_errors, 0,
"Found code style errors (and warning).")
class TestDocsB(unittest.TestCase):
""" check for documentation """
def test_module_doc(self):
""" check for module documentation """
self.assertTrue(len(file_storage.__doc__) > 0)
def test_class_doc(self):
""" check for documentation """
self.assertTrue(len(FileStorage.__doc__) > 0)
def test_method_docs(self):
""" check for method documentation """
for func in dir(FileStorage):
self.assertTrue(len(func.__doc__) > 0)
class BaseModelclassTests(unittest.TestCase):
""" Test Case for base_model moudle """
def setUp(self):
""" Create instance global """
self.ins0 = FileStorage()
self.ins1 = FileStorage()
def tearDown(self):
""" Clean All test case """
pass
def test_permissions(self):
"""test read-write-execute permissions"""
read = os.access('models/engine/file_storage.py', os.R_OK)
self.assertTrue(read)
write = os.access('models/engine/file_storage.py', os.W_OK)
self.assertTrue(write)
exe = os.access('models/engine/file_storage.py', os.X_OK)
self.assertTrue(exe)
def test_isinstance(self):
""" Test if a variable is instance of FileStorage """
self.assertIsInstance(self.ins0, FileStorage)
def test_all(self):
""" The dict return is a dictionary """
dic = self.ins0.all()
self.assertEqual(type(dic), dict)
self.assertIs(dic, self.ins0._FileStorage__objects)
if __name__ == '__main__':
unittest.main()
# Run Test
# python3 -m unittest discover tests
# python3 -m unittest tests/test_models/test_engine/test_file_storage.py