Completed
Push — master ( 1019d4...eef64e )
by srz
03:26
created

nofused_iuwandbox_test.setUp()   B

Complexity

Conditions 5

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
c 3
b 0
f 0
dl 0
loc 11
rs 8.5454
1
#!/usr/bin/env python
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
#
3
# test_iuwandbox.py
4
#
5
6
from __future__ import print_function
7
8
import sys
9
import os
10
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../fused')
11
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../wandbox')
12
13
try:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
14
    import unittest2 as unittest
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Configuration introduced by
The import unittest2 could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
15
except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
16
    import unittest
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
17
import iuwandbox
18
import fused_iutest_files
0 ignored issues
show
Configuration introduced by
The import fused_iutest_files could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
19
import shutil
20
21
try:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
22
    from StringIO import StringIO
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
23
except ImportError:
24
    from io import StringIO
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
25
26
root = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../../../')
27
fused_src = root + '/fused-src'
28
test_src = root + '/test/syntax_tests.cpp'
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
29
test_opt_default = [ '--encoding', 'utf-8-sig' ]
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
Coding Style introduced by
No space allowed after bracket
test_opt_default = [ '--encoding', 'utf-8-sig' ]
^
Loading history...
Coding Style introduced by
No space allowed before bracket
test_opt_default = [ '--encoding', 'utf-8-sig' ]
^
Loading history...
30
test_opt_nomain = test_opt_default
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
31
test_opt = [ '-f"-DIUTEST_USE_MAIN"' ]
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
Coding Style introduced by
No space allowed after bracket
test_opt = [ '-f"-DIUTEST_USE_MAIN"' ]
^
Loading history...
Coding Style introduced by
No space allowed before bracket
test_opt = [ '-f"-DIUTEST_USE_MAIN"' ]
^
Loading history...
32
test_opt.extend(test_opt_default)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 0 spaces were expected, but 1 were found.
Loading history...
33
34
35
def eprint(*args, **kwargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
36
    print(*args, file=sys.stderr, **kwargs)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
37
38
39
class iuwandbox_test_base(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
40
    dir = None
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
41
42
    def setUp(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
43
        self.capture = StringIO()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
44
        sys.stdout = self.capture
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
45
        self.dir = os.getcwd()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
46
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
47
        return super(iuwandbox_test_base, self).setUp()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
48
49
    def tearDown(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
50
        sys.stdout = sys.__stdout__
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
51
        os.chdir(self.dir)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
52
        self.capture.close()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
53
        return super(iuwandbox_test_base, self).tearDown()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
54
55
    def dump(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
56
        value = self.capture.getvalue()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
57
        eprint(value)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
58
59
60
class nofused_iuwandbox_test(iuwandbox_test_base):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
61
    def setUp(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
62
        if 'SCRUTINIZER' in os.environ:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
63
            self.skipTest('this test is not run on SCRUTINIZER.')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
64
        if os.path.exists(fused_src):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
65
            try:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
66
                shutil.rmtree(fused_src)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
67
            except:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
68
                pass
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
69
        if os.path.exists(os.path.join(fused_src, 'iutest.min.hpp')):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
70
            self.skipTest('fused-src is exists')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
71
        return super(nofused_iuwandbox_test, self).setUp()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
72
73 View Code Duplication
    def test_nofused(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
74
        sys.argv[1:] = [ test_src ]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
No space allowed after bracket
sys.argv[1:] = [ test_src ]
^
Loading history...
Coding Style introduced by
No space allowed before bracket
sys.argv[1:] = [ test_src ]
^
Loading history...
75
        sys.argv.extend(test_opt)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
76
        with self.assertRaises(SystemExit) as cm:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
77
            iuwandbox.main()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
78
        self.dump()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
79
        self.assertEqual(cm.exception.code, 1, self.capture.getvalue())
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
80
        self.assertRegex(self.capture.getvalue(), '.*please try \"make fused\".*')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
81
82
83
class iuwandbox_test(iuwandbox_test_base):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
84
    def setUp(self):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
85
        if not os.path.exists(fused_src):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
86
            try:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
87
                fused_iutest_files.FusedAll(fused_iutest_files.IUTEST_INCLUDE_DIR, fused_src)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
88
#              os.system('python ' + root + '/tools/fused/fused_iutest_files.py ' + fused_src)
89
            except:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
90
                pass
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Unused Code introduced by
This except handler seems to be unused and could be removed.

Except handlers which only contain pass and do not have an else clause can usually simply be removed:

try:
    raises_exception()
except:  # Could be removed
    pass
Loading history...
91
        if not os.path.exists(os.path.join(fused_src, 'iutest.min.hpp')):
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
92
            self.skipTest('fused-src is not exists')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
93
        return super(iuwandbox_test, self).setUp()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
94
95 View Code Duplication
    def test_nomain(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
96
        sys.argv = sys.argv[:1]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
97
        sys.argv[1:] = [ test_src ]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
No space allowed after bracket
sys.argv[1:] = [ test_src ]
^
Loading history...
Coding Style introduced by
No space allowed before bracket
sys.argv[1:] = [ test_src ]
^
Loading history...
98
        sys.argv.extend(test_opt_nomain)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
99
        with self.assertRaises(SystemExit) as cm:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
100
            iuwandbox.main()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
101
        self.dump()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
102
        self.assertEqual(cm.exception.code, 1, self.capture.getvalue())
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
103
        self.assertRegex(self.capture.getvalue(), '.*hint:.*')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
104
        self.assertRegex(self.capture.getvalue(), '.*If you do not use boost test, please specify the file with the main function first..*')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (140/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
105
106 View Code Duplication
    def test_run(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
107
        sys.argv[1:] = [ test_src ]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
No space allowed after bracket
sys.argv[1:] = [ test_src ]
^
Loading history...
Coding Style introduced by
No space allowed before bracket
sys.argv[1:] = [ test_src ]
^
Loading history...
108
        sys.argv.extend(test_opt)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
109
        print(sys.argv)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
110
        with self.assertRaises(SystemExit) as cm:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
111
            iuwandbox.main()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
112
        self.dump()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
113
        self.assertEqual(cm.exception.code, 0, self.capture.getvalue())
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
114
        self.assertRegex(self.capture.getvalue(), '.*OK.*')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
115
116 View Code Duplication
    def test_same_filename(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
117
        sys.argv[1:] = [ 'src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp' ]
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
No space allowed after bracket
sys.argv[1:] = [ 'src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp' ]
^
Loading history...
Coding Style introduced by
No space allowed before bracket
sys.argv[1:] = [ 'src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp' ]
^
Loading history...
118
        sys.argv.extend(test_opt_nomain)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
119
        print(sys.argv)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
120
        with self.assertRaises(SystemExit) as cm:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
121
            iuwandbox.main()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
122
        self.dump()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
123
        self.assertEqual(cm.exception.code, 0, self.capture.getvalue())
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
124
        self.assertRegex(self.capture.getvalue(), '.*OK.*')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
125
126
if __name__ == "__main__":
127
    unittest.main()
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
128