tests.TestParseArgs.test_conf_file()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 12
rs 9.4286
1
#
2
# Copyright 2014 Quantopian, Inc.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
import os
17
from unittest import TestCase
18
from six import iteritems
19
20
from zipline.utils import parse_args
21
from zipline.utils import cli
22
23
24
class TestParseArgs(TestCase):
25
    def test_defaults(self):
26
        args = parse_args([])
27
        for k, v in iteritems(cli.DEFAULTS):
28
            self.assertEqual(v, args[k])
29
30
    def write_conf_file(self):
31
        conf_str = """
32
[Defaults]
33
algofile=test.py
34
symbols=test_symbols
35
start=1990-1-1
36
        """
37
38
        with open('test.conf', 'w') as fd:
39
            fd.write(conf_str)
40
41
    def test_conf_file(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
        self.write_conf_file()
43
        try:
44
            args = parse_args(['-c', 'test.conf'])
45
46
            self.assertEqual(args['algofile'], 'test.py')
47
            self.assertEqual(args['symbols'], 'test_symbols')
48
            self.assertEqual(args['start'], '1990-1-1')
49
            self.assertEqual(args['data_frequency'],
50
                             cli.DEFAULTS['data_frequency'])
51
        finally:
52
            os.remove('test.conf')
53
54
    def test_overwrite(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
        self.write_conf_file()
56
57
        try:
58
            args = parse_args(['-c', 'test.conf', '--start', '1992-1-1',
59
                               '--algofile', 'test2.py'])
60
61
            # Overwritten values
62
            self.assertEqual(args['algofile'], 'test2.py')
63
            self.assertEqual(args['start'], '1992-1-1')
64
            # Non-overwritten values
65
            self.assertEqual(args['symbols'], 'test_symbols')
66
            # Default values
67
            self.assertEqual(args['data_frequency'],
68
                             cli.DEFAULTS['data_frequency'])
69
        finally:
70
            os.remove('test.conf')
71