generate.py specifies encoding for test files

On many Windows systems, the default encoding is not utf-8. If there are test files containing non-ASCII characters that do not map properly to the default encoding, generate.py crashes.

Migrated from [libgit2#2247](https://github.com/libgit2/libgit2/pull/2247)