Posts

Showing posts with the label timer

test timers in react, sinon or jest

test timers in react, sinon or jest I have a funtion checkIdleTime , being set to be called periodically. checkIdleTime componentDidMount() { var idleCheck = setInterval(this.checkIdleTime.bind(this), authTimeoutSeconds * 1000); this.setState({idleCheck: idleCheck}); document.onkeypress = this.setActive; } I want to use the fake timer for test, but can't figure out how, tried sinon and jest . sinon jest beforeEach(() => { checkIdleTime = jest.spyOn(PureMain.prototype, 'checkIdleTime'); wrapper = shallow( <PureMain/> ); jest.useFakeTimers(); //clock = sinon.useFakeTimers(); }); it('should check the idle time after [authTimeoutSeconds] seconds of inactivity', () => { wrapper.instance().componentDidMount(); var idleCheck_timeout = wrapper.instance().state.idleCheck; expect(idleCheck_timeout).not.toEqual(null); expect(idleCheck_timeout._idleTimeout).toBe(authTimeoutSeconds * 1000); jest.runAllTi...

Pandas Datareader with Morningstar

Pandas Datareader with Morningstar I'm web scraping with pandas and using morningstar's API. Every now and then I scrape a website with a ticker that morningstar struggles with and crashes python. I've included relevant lines below and it almost always work and I don't think my code is causing the errors but I can't get around pandas freezing up on me. Date is a variable here that is in the correct format for DataReader, it doesn't raise problems. import pandas as pd import pandas_datareader.data as web df = web.DataReader(ticker, "morningstar", date) If a ticker is getting stuck, after a couple minutes pandas will print (on it's own, not my print statement) the phrase "adding (insert ticker here) to retry list". Shortly after the message pops up I get a pop up window saying "Python quit unexpectedly". I've tried to wrap the datareader in a while loop with a timer to stop it and move on to the next ticker but it didn't w...