GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 73c5c0...bade8b )
by Drew J.
43s
created

TestCliCfgManipulation   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 57.58 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 38
loc 66
rs 10
wmc 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# -*- coding: utf-8 -*-
2
import unittest
3
from mock import patch, call, MagicMock, mock_open
4
from awslambdahelper.cli import SetupCfgFile
5
6
7
class TestCliCfgManipulation(unittest.TestCase):
8
    def test_instantiation(self):
9
        setup = SetupCfgFile('setup', 'temp')
10
11
        self.assertEqual(setup.setup_cfg, 'setup')
12
        self.assertEqual(setup.temp_setup_cfg, 'temp')
13
14
    @patch('os.path.exists')
15
    def test_loadexists(self, path_exists):
16
        setup = SetupCfgFile('setup', 'temp')
17
18
        setup.read = MagicMock()
19
        path_exists.return_value = True
20
        setup.load()
21
22
        setup.read.assert_called_once_with('setup')
23
24
    @patch('os.path.exists')
25
    def test_loadnotexist(self, path_exists):
26
        setup = SetupCfgFile('setup', 'temp')
27
28
        setup.read = MagicMock()
29
        path_exists.return_value = False
30
        setup.load()
31
32
        setup.read.assert_not_called()
33
34
    @patch('ConfigParser.ConfigParser.write')
35
    def test_writeexistinginstall(self, super_write):
36
        """
37
        Test the case where we already have 'install' entry in our setup.cfg
38
        """
39
        setup = SetupCfgFile('setup', 'temp')
40
        setup.sections = MagicMock()
41
        setup.set = MagicMock()
42
        setup.add_section = MagicMock()
43
44
        setup.sections.return_value = ['install']
45
46
        m = mock_open()
47
        with patch('__builtin__.open', m):
48
            setup.write()
49
50
        setup.add_section.assert_not_called()
51
        setup.set.assert_called_once_with('install', 'prefix', '')
52
        m.assert_called_once_with('temp', 'w')
53
54
    @patch('ConfigParser.ConfigParser.write')
55
    def test_writemissinginstall(self, super_write):
56
        """
57
        Test the case where we already have 'install' entry in our setup.cfg
58
        """
59
        setup = SetupCfgFile('setup', 'temp')
60
        setup.sections = MagicMock()
61
        setup.set = MagicMock()
62
        setup.add_section = MagicMock()
63
64
        setup.sections.return_value = []
65
66
        m = mock_open()
67
        with patch('__builtin__.open', m):
68
            setup.write()
69
70
        setup.add_section.assert_called_once_with('install')
71
        setup.set.assert_called_once_with('install', 'prefix', '')
72
        m.assert_called_once_with('temp', 'w')
73