TestUserAPIAccess   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 82.76 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 24
loc 29
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_getAllTrainsForLine() 12 12 3
A test_getAllTrainsForStation() 12 12 3
A setUp() 0 2 1

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
import unittest
2
from tube.tubeAPI import Tube
3
from tube.tubeAPI import TubeLine, TubeStation, TubeStationLinePlatform
4
from tube.tubeAPI import TubePlatform, TubeTrain
5
6
import vcr
7
8
my_vcr = vcr.VCR(
9
	serializer = 'json',
10
	cassette_library_dir = 'tube/tests/fixtures/cassettes',
11
	record_mode = 'once',
12
)
13
14
import logging
15
16
logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from vcrpy
17
vcr_log = logging.getLogger("vcr")
18
vcr_log.setLevel(logging.DEBUG)
19
20
class TestUserAPIAccess(unittest.TestCase):
21
    def setUp(self):
22
        self.tube = Tube()
23
24 View Code Duplication
    def test_getAllTrainsForStation(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
25
        with my_vcr.use_cassette('User-All-Station-KXX.json'):
26
            trains = self.tube.getAllTrainsForStation("KXX")
27
            self.assertIsInstance( trains, list )
28
            self.assertIsInstance( trains[0], TubeTrain )
29
            self.assertEqual( len(trains), 110 )
30
        with my_vcr.use_cassette('User-All-Station-KXX.json'):
31
            kxx = self.tube.map.get(stationcode="KXX")
32
            trains = self.tube.getAllTrainsForStation(kxx)
33
            self.assertIsInstance( trains, list )
34
            self.assertIsInstance( trains[0], TubeTrain )
35
            self.assertEqual( len(trains), 110 )
36
37 View Code Duplication
    def test_getAllTrainsForLine(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
38
        with my_vcr.use_cassette('User-All-Line-North.json'):
39
            trains = self.tube.getAllTrainsForLine("N")
40
            self.assertIsInstance( trains, list )
41
            self.assertIsInstance( trains[0], TubeTrain )
42
            self.assertEqual( len(trains), 152 )
43
        with my_vcr.use_cassette('User-All-Line-North.json'):
44
            northern = self.tube.map.get(linecode="N")
45
            trains = self.tube.getAllTrainsForLine(northern)
46
            self.assertIsInstance( trains, list )
47
            self.assertIsInstance( trains[0], TubeTrain )
48
            self.assertEqual( len(trains), 152 )
49