예제 #1
0
    def test_plot(self):
        '''This function will test if plots from year 2007 to 2012 are generated successfully'''
        try:
            for i in range(2007,2013):
                os.remove('./Income_Box_'+str(i)+'.jpg')
                os.remove('./Income_Hist_'+str(i)+'.jpg')

        except OSError:
            pass
        i = Income()
        i.plot_2007_2012()
        for i in range(2007,2013):
            self.assertTrue(os.path.isfile('./Income_Box_'+str(i)+'.jpg'), "Fail to generate plot.")
            self.assertTrue(os.path.isfile('./Income_Hist_'+str(i)+'.jpg'), "Fail to generate plot.")
예제 #2
0
def main():
    income_data = Income()
    # Ask user for a year and exit until 'finish' entered.
    user_input = get_user_input()
    while user_input != "finish":
        year = 0
        while year == 0:
            try:
                year = read_year(user_input)
                income_data.income_dist(year)
                break
            except ValueError:
                print "Invalid input. Please enter again."
            except RangeError:
                print "The year you entered is not in [1800, 2012]. Please enter again."
            user_input = get_user_input()
        user_input = get_user_input()
    # plot income data from 2007 to 2015
    income_data.plot_2007_2012()