Show expected and actual values for assertion failures - node.js

When writing assertions for my tests, the assertion failures don't provide enough information without needing to open an IDE and start debugging.
For example, I have some code that uses the 'assert' library:
import * as assert from 'assert'
// some code
assert(someObject.getValue() === 0)
I just get
AssertionError [ERR_ASSERTION]: false == true
+ expected - actual
-false
+true
This error message isn't really meaningful. As a workaround, I added it in the message in the assertion:
assert(someObject.getValue() === 0,
'\nActual: ' + someObject.getValue() +
'\nExpected: ' + 0)
Is there a better, cleaner way to just show the expected & actual values without overriding the message on every assertion? I also tried to create an assert wrapper, but I wasn't able to extract the actual and expected values from the expression.
EDIT: assert.strictEqual resolves this issue for equalities only. But as soon as any other operator is included, then we have the same issue (e.g. assert(someObject.getValue() > 0)
Any advice would be appreciated.
Thanks!

You can use assert.strictEqual(actual, expected[, message]) to get actual/expected error messages without the need of the third message argument:
assert.strictEqual(someObject.getValue(), 0)
You'd get an error message such as:
// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
//
// 1 !== 0
Hopefully that helps!

Related

Binance API in python APIError(code=-1121): Invalid symbol

I am trying to code a binance Buy function. However the code
from binance.enums import *
order = client.create_order(symbol='DOGEUSDT', side = 'BUY', type = 'MARKET', quantity = 475, timeInForce='GTC')
this code outputs > APIError(code=-1121): Invalid symbol.
Also, for the same symbol,
print(client.get_symbol_info(symbol="DOGEUSDT"))
ouptuts > None
The symbol DOGEUSDT exists is the orderbook. https://api.binance.com/api/v3/ticker/bookTicker
I dont know why the same symbol I get from binance is invalid.
Are you using the testnet? I had the same error, however when I removed testnet=True from the client initialization the error was resolved.
two things can happen
client.API_URL = https://testnet.binance.vision/api
in that case change it to
https://api.binance.com/api
Client(api_key, secret_key, testnet=True)
in that case change testnet=False or delete it

soapui free version assertions request = response

I will pass any memberid or active card for matching to verify activecard(cardno) matches memberid passed.
Request:
<MemberID>${Property Looper#memberid}</MemberID>
<CardNo>${Property Looper#ActiveCard}</CardNo>
Expected result:
<ReturnMessage>Cardno not found</ReturnMessage>
OR
<ReturnMessage>SUCCESS</ReturnMessage>
How to put assertions to check if the member id in request will check matching with response? contains and not contains assertions seems like not working that well for this condition?
and i want the test to be passed even if the matching failed as the ultimate goal is to make sure the error is not from the data (the test pass regardless the return status) but the application. Thanks
Edit:
after running the step
Edit 2:
after running script assertion
custom property added
You can use Script Assertion to achieve the same.
Based on the description, the assertion should be able to handle both below cases :
some case, you may expect card not found
some case, you may expect SUCCESS
Define test case level custom property, say EXPECTED_MESSAGE and provide appropriate expected value depending on the case.
Add below script assertion for the SOAP Request test step.
//Check if the response is received
assert context.response, 'Response is empty or null'
//Parse the response and find the ReturnMessage value
def actualMessage = new XmlSlurper().parseText(context.response).'**'.find{it.name() == 'ReturnMessage'}?.text()
log.info "Return message from response: $actualMessage"
//Read the expected message from custom property
def expectedMessage = context.expand('${#TestCase#EXPECTED_MESSAGE}')
//Verify with actual value
assert actualMessage == expectedMessage
Let us assume the output is like
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ReturnMessage>SUCCESS</ReturnMessage>
</soap:Body>
</soap:Envelope>
you can use the below script assertion
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def response = groovyUtils.getXmlHolder("First Step#Response")
String x = response.getNodeValue("//*[local-name()='ReturnMessage']")
if(x.contains("Cardno not found" ) || x.contains("SUCCESS"))
{
log.info "Success"
}
else
{
log.info " Fail"
}
output is
Sat Oct 28 15:22:02 IST 2017:INFO:Success
Rao's approach is also correct. Its just that if you are following that approach you have to have 2 expected result custom properties since you have 2 properties.
You may have to use if condition before assertion as 1 assertion will fail because your results would be either "Cardno not found" or "SUCCESS"
2 Changes you might have to make in the script. replace 'First Step' with the name of your teststep
change the getNodeValue step to reach the actual place

Invalid Syntax for PEP-8

I'm receiving a notification that advised the below script is not PEP-8:
example_var = print('whoa')
Output:
[E] invalid syntax.
It's showing that the error is a result of the first parentheses in the print statement, but nothing looks off to me.
example_var = print('whoa')
example_var

GML room_goto() Error, Expecting Number

I'm trying to make a game that chooses a room from a pool of rooms using GML, but I get the following error:
FATAL ERROR in action number 3 of Create Event for object obj_control:
room_goto argument 1 incorrect type (5) expecting a Number (YYGI32)
at gml_Object_obj_control_CreateEvent_3 (line 20) - room_goto(returnRoom)
pool = ds_list_create()
ds_list_insert(pool, 0, rm_roomOne)
ds_list_insert(pool, 1, rm_roomTwo)
ds_list_insert(pool, 2, rm_roomThree)
ds_list_insert(pool, 3, rm_roomFour)
var returnIndex;
var returnRoom;
returnIndex = irandom(ds_list_size(pool))
returnRoom = ds_list_find_value(pool, returnIndex)
if (ds_list_size(pool) == 0){
room_goto(rm_menu_screen)
}else{
room_goto(returnRoom)
}
I don't get the error message saying it's expecting a number.
This is weird indeed... I think this should actually work.. But I have no GM around to test :(
For now you can also solve this using "choose". This saves a list (and saves memory, because you're not cleaning up the list by deleting it - thus it resides in memory)
room_goto(choose(rm_roomOne, rm_roomTwo, rm_roomThree, rm_roomFour));
choose basically does exactly what you're looking for. Might not be the best way to go if you're re-using the group of items though.

What's the correct way to check sql found condition in ILE RPG?

When working with embedded SQL in RPG, you often end up with a cursor and a dow-loop for processing all rows in your result. The condition in the loop is somehow dependent on SQLCOD and/or SQLSTT, some globally available variables in an SQLRPGLE-program?
But what is the correct way of checking these values? Some suggest SQLCOD = 0 others not (SQLCOD = +100 or SQLSTT = '02000'). One fails on all warnings, the other does not fail on some errors, so I'm not content.
To illustrate what I do with some code:
Pmain B
D PI
Dmy_ds E DS extname(SOME_TABLE)
D qualified
/free
exec sql
DECLARE cur CURSOR FOR
SELECT *
FROM some_table;
exec sql
OPEN cur;
exec sql
FETCH cur
INTO :my_ds;
dow sql_found();
exec sql
FETCH cur
INTO :my_ds;
enddo;
exec sql
CLOSE cur;
/end-free
Pmain E
Psql_found B
D PI N
/free
// insert return statement here...
/end-free
Psql_found E
I'm looking for the correct return statement here, that will make me go through all rows if no error occurs and lets me leave when an error occurs. Bonus points for some decent way to check for errors.
SQLSTATE is better, and recommended by IBM.
From IBM's InfoCenter SQL Messages and Codes Reference: SQLCODE and SQLSTATE concepts
SQLSTATE is the preferred standard return code.
SQLSTATE is 5 characters, with the first two bytes identifying a class of conditions.
'00' = Unqualified Successful Completion
'01' = Warning
'02' = No Data
Anything else is an error. I generally only check for '00'.
Simple. Easy. More portable.
Using SQLCODE often involves lists of codes which are, IMHO, less than developer friendly.
Example:
Personally, I generally include definitions and code like this:
D xSQLState# s * inz( %addr(SQLState) )
D xSQLState ds 5 based(xSQLState#)
D xSQLState2 2a
D
D Success_On_SQL C const('00')
D Warning_On_SQL C const('01')
D NoData_On_SQL C const('02')
Then after any SQL operation, I generally check
if xSQLState2 <> Success_On_Sql;
someflag = true;
endif;
The best practice is to process the SQLCODEs you expect (as part of the expected processing) and to add exception code to handle the ones you don't. One implementation:
dow 1=1; // forever
exec sql
FETCH cur
INTO :my_ds;
// normal exit
if sqlstt = SQL_NODATA;
SFLEND = *on;
leave;
endif;
// can't CAST a value
if sqlstt = SQL_CAST; // CAST error
... tell user there's an error and read another
iter;
endif;
// decimal data error
if sqlstt = SQL_DDE;
tell user to call IT and stop reading
leave;
endif;
// whoops! not expected at all. Dump for post-mortem
if sqlstt <> SQL_NORMAL;
... tell user to call IT and stop reading
dump(a);
leave;
endif;
// test for end of loop
// filled subfile page?
enddo; // forever
With this type of implementation you have to intentionally leave the loop; whether you've filled a subfile page, loaded the highest element in an array or hit an error. I'm not sure there is a single, generic implementation that will handle all circumstances. Sometimes you might want to leave the read loop if you have a record lock and sometimes you want to issue a message and try again (for example).
I did some more searching on the topic and found something on IBM's site (quote):
The SQLCODE is also set by the database manager after each SQL
statement is executed as follows:
- If SQLCODE = 0 and SQLWARN0 is blank, execution was successful.
- If SQLCODE = 100, no data was found. For example, a FETCH
statement returned no data, because the cursor was positioned
after the last row of the result table.
- If SQLCODE > 0 and not = 100, execution was successful with a
warning.
- If SQLCODE = 0 and SQLWARN0 = 'W', execution was successful
with a warning.
- If SQLCODE < 0, execution was not successful.
Which would lead me to an sql_found() like this:
Pfound_sql B
D PI N
/free
return (SQLCOD >= 0) and (SQLCOD<>100);
/end-free
Pfound_sql E
That should take care of the End of Data condition and fail on all errors. I'm not sure if there are some warnings that I should take care of (don't want to get trapped in an endless loop, if there is a warning that leads to not reading).

Resources