TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.86k stars 215 forks source link

How to write a module and test it #869

Open fdsgdshn opened 7 months ago

fdsgdshn commented 7 months ago

Hi,

I'm looking to create a module in Transcrypt and also write an auto-test module for it. What steps should I take to accomplish this? I've created a file named enum_new under transcrypt/modules/enum_new, and I've defined a class named MyEnum within it. However, when I try to test it under transcrypt/development/automated_tests/transcrypt/module_enum/ , even after importing the class, it seems to be inaccessible. Could you provide some guidance on this matter?

The error message is as follows:

from enum_new import * ModuleNotFoundError: No module named 'enum_new' Aborted

But python couldn't find this new module named enum_new.

Thanks!

JennaSys commented 5 months ago

It sounds like you are running into namespace issues. Are you using an __init__.py file in the modules/enum_new/ and automated_tests/transcrypt/module_enum/ folders?

In module_enum/__init__.py you should be able to import your class normally and then use it in a call to autoTester.check() to set up the test.

You will also need to import module_enum and add a call to autoTester.run (module_enum, 'module_enum') in automated_tests/transcrypt/autotest.py to have it actually run as part of the automated tests for transcrypt.