Refactor 'test_generator_basic': extract common parts to separate functions

--HG--
extra : histedit_source : 48c11e7e1cc8d235d72d3bea9bfc1593dfc5e141%2Cc66be3277dbd71ea4815cd153f91089683bd6f07