Example #1
0
 def test_parse_valid_positions(self):
     '''
     Test that parse_positions on a list_as_string returns a list of InvestmentPosition objects.
     '''
     self.assertEqual(InvestmentPositions.parse_positions("[1, 10, 100, 1000]"),
         [InvestmentPositions(position, int(1000 / position)) for position in [1, 10, 100, 1000]]
         )
Example #2
0
 def test_parse_positions_valid_repeated_vals(self):
     '''
     Test that parse_positions accepts repeated valid positions and returns list of InvestmentPosition objects.
     '''
     self.assertEqual(InvestmentPositions.parse_positions("[1, 10, 10, 100, 1000, 1]"),
         [InvestmentPositions(position, int(1000 / position)) for position in [1, 10, 10, 100, 1000, 1]]
         )
Example #3
0
 def test_parse_positions_valid_repeated_vals(self):
     '''
     Test that parse_positions accepts repeated valid positions and returns list of InvestmentPosition objects.
     '''
     self.assertEqual(
         InvestmentPositions.parse_positions("[1, 10, 10, 100, 1000, 1]"), [
             InvestmentPositions(position, int(1000 / position))
             for position in [1, 10, 10, 100, 1000, 1]
         ])
Example #4
0
 def test_parse_valid_positions(self):
     '''
     Test that parse_positions on a list_as_string returns a list of InvestmentPosition objects.
     '''
     self.assertEqual(
         InvestmentPositions.parse_positions("[1, 10, 100, 1000]"), [
             InvestmentPositions(position, int(1000 / position))
             for position in [1, 10, 100, 1000]
         ])
Example #5
0
def prompt_positions():
    '''
    Prompt user and read in keyboard input of investment positions
    Raises InvalidListError, InvalidPositionError, ValueError for incorrect inputs
    '''
    
    while True:
        try:
            userinput = input("Enter the positions as a list with one space after each comma.")
            return InvestmentPositions.parse_positions(userinput)
        
        except (InvalidListError, InvalidPositionError, ValueError) as e:
            print(e)
Example #6
0
 def test_parse_positions_invalid_format(self):
     '''
     Test parse_positions raises InvalidListError if list_as_string is not in "list" format.
     '''
     with self.assertRaises(InvalidListError):
         InvestmentPositions.parse_positions("1, 10, 100, 1000")
Example #7
0
 def test_parse_invalid_positions(self):
     '''
     Invalid position value (5) raises InvalidPositionError
     '''
     with self.assertRaises(InvalidPositionError):
         InvestmentPositions.parse_positions("[1, 5, 100, 1000]")
Example #8
0
 def test_parse_positions_invalid_format(self):
     '''
     Test parse_positions raises InvalidListError if list_as_string is not in "list" format.
     '''
     with self.assertRaises(InvalidListError):
         InvestmentPositions.parse_positions("1, 10, 100, 1000")
Example #9
0
 def test_parse_invalid_positions(self):
     '''
     Invalid position value (5) raises InvalidPositionError
     '''
     with self.assertRaises(InvalidPositionError):
         InvestmentPositions.parse_positions("[1, 5, 100, 1000]")