TestFileOperations   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 43
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 8 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/project_locale'),
19
                                 'localizations_compile.py'))
20
21
    def test_file_statistics(self):
22
        class_fo = FileOperations()
23
        value_to_assert = class_fo.fn_get_file_statistics({'file name': __file__})['size [bytes]']
24
        value_to_compare_with = os.path.getsize(__file__)
25
        self.assertEqual(value_to_assert, value_to_compare_with)
26
27
    def test_file_dates(self):
28
        class_fo = FileOperations()
29
        value_to_assert = class_fo.fn_get_file_dates(__file__)['created']
30
        value_to_compare_with = datetime.fromtimestamp(os.path.getctime(__file__))
31
        self.assertEqual(value_to_assert, value_to_compare_with)
32
33
    def test_file_verdict(self):
34
        class_ln = LoggingNeeds()
35
        class_ln.initiate_logger('None', __file__)
36
        class_fo = FileOperations()
37
        ref_datetime = os.path.getctime(__file__)
38
        relevant_file = os.path.join(
39
            os.path.dirname(__file__).replace('test', 'sources'), 'project_locale/__init__.py')
40
        value_to_assert = class_fo.fn_get_file_datetime_verdict(
41
            class_ln.logger, relevant_file, 'created', ref_datetime)
42
        self.assertEqual(value_to_assert, class_fo.locale.gettext('older'))
43