Passed
Push — master ( 074b4c...d425e3 )
by Daniel
03:22
created

TestFileOperations   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestFileOperations.test_file_statistics() 0 5 1
A TestFileOperations.test_file_verdict() 0 10 1
A TestFileOperations.setUp() 0 7 2
A TestFileOperations.test_file_dates() 0 5 1
1
from datetime import datetime
2
import os
3
from db_extractor.LoggingNeeds import LoggingNeeds
4
from db_extractor.FileOperations import FileOperations
5
import unittest
6
# package to facilitate multiple operation system operations
7
import platform
8
9
10
class TestFileOperations(unittest.TestCase):
11
12
    def setUp(self) -> None:
13
        python_binary = 'python'
14
        if platform.system() == 'Windows':
15
            python_binary += '.exe'
16
        os.system(python_binary + ' '
17
                  + os.path.join(os.path.normpath(os.path.dirname(__file__))
18
                                 .replace('test', 'sources'), 'localizations_compile.py'))
19
20
    def test_file_statistics(self):
21
        class_fo = FileOperations()
22
        value_to_assert = class_fo.fn_get_file_statistics(__file__)['size [bytes]']
23
        value_to_compare_with = os.path.getsize(__file__)
24
        self.assertEqual(value_to_assert, value_to_compare_with)
25
26
    def test_file_dates(self):
27
        class_fo = FileOperations()
28
        value_to_assert = class_fo.fn_get_file_dates(__file__)['created']
29
        value_to_compare_with = datetime.fromtimestamp(os.path.getctime(__file__))
30
        self.assertEqual(value_to_assert, value_to_compare_with)
31
32
    def test_file_verdict(self):
33
        class_ln = LoggingNeeds()
34
        class_ln.initiate_logger('None', __file__)
35
        class_fo = FileOperations()
36
        ref_datetime = os.path.getctime(__file__)
37
        relevant_file = os.path.join(
38
            os.path.dirname(__file__).replace('test', 'sources'), 'project_locale/__init__.py')
39
        value_to_assert = class_fo.fn_get_file_datetime_verdict(
40
            class_ln.logger, relevant_file, 'created', ref_datetime)
41
        self.assertEqual(value_to_assert, class_fo.locale.gettext('older'))
42