def initRates(self, inputCandle: str) -> list: """ Parse the inputCandle string into a list of three `rates`. Args: inputCandle (str): the input command to be parsed. Returns: list: such as [Rate, Rate, Rate] """ # Split input string (cut by a semi-colon) inputsRate = inputCandle.split(sep=";") if len(inputsRate) is not 3: Logger("There might be three rates per candle.") self._state = globals.INVALID return None outputRates = [ Rate(inputsRate[0]), Rate(inputsRate[1]), Rate(inputsRate[2]) ] # Check for rates' validity for rate in outputRates: if rate._state is globals.INVALID: Logger("Candle is invalid") self._state = globals.INVALID return outputRates
def test_twiceSameCurrency(caplog): rate = Rate("USDT_USDT,1516147200,11600.12523891,11032.9211865,11041.42197477,11214.06052489,volume") assert rate._state == globals.INVALID with caplog.at_level(logging.ERROR): assert caplog.records[0].message == "Two times the same currency."
def test_normalCase(): rate = Rate("USDT_BTC,1516147200,11600.12523891,11032.9211865,11041.42197477,11214.06052489,4123273.6568455") assert rate._state == globals.VALID assert rate._currency1 == "USDT" assert rate._currency2 == "BTC" assert rate._date == 1516147200 assert rate._high == 11600.12523891 assert rate._low == 11032.9211865 assert rate._open == 11041.42197477 assert rate._close == 11214.06052489 assert rate._volume == 4123273.6568455
def test_wrongVolumeValue(): rate = Rate("USDT_BTC,1516147200,11600.12523891,11032.9211865,11041.42197477,11214.06052489,volume") assert rate._state == globals.INVALID
def test_wrongCloseValue(): rate = Rate("USDT_BTC,1516147200,11600.12523891,11032.9211865,11041.42197477,close,4123273.6568455") assert rate._state == globals.INVALID
def test_wrongOpenValue(): rate = Rate("USDT_BTC,1516147200,11600.12523891,11032.9211865,open,11214.06052489,4123273.6568455") assert rate._state == globals.INVALID
def test_wrongLowValue(): rate = Rate("USDT_BTC,1516147200,11600.12523891,low,11041.42197477,11214.06052489,4123273.6568455") assert rate._state == globals.INVALID
def test_wrongHighValue(): rate = Rate("USDT_BTC,1516147200,high,11032.9211865,11041.42197477,11214.06052489,4123273.6568455") assert rate._state == globals.INVALID
def test_wrongDate(): rate = Rate("USDT_BTC,date,11600.12523891,11032.9211865,11041.42197477,11214.06052489,4123273.6568455") assert rate._state == globals.INVALID
def test_wrongPairSecondIsNotValidCurrency(): rate = Rate("USDT_WRONG,1516147200,11600.12523891,11032.9211865,11041.42197477,11214.06052489,4123273.6568455") assert rate._state == globals.INVALID
def test_wrongPairFormat(): rate = Rate("USDT-BTC,1516147200,11600.12523891,11032.9211865,11041.42197477,11214.06052489,4123273.6568455") assert rate._state == globals.INVALID