jeffwright13 / audio_program_generator

Generates an audio program from a text file that contains phrases
MIT License
8 stars 2 forks source link

Add unit tests! #10

Closed jeffwright13 closed 3 years ago

jeffwright13 commented 3 years ago

I mean, come on!

bbelderbos commented 3 years ago

LOL

bbelderbos commented 3 years ago

Btw I hit a nice use case of unit vs integration test this weekend, FYI: https://github.com/bbelderbos/git-stats/tree/main/tests

jeffwright13 commented 3 years ago

Main stumbling block right now is the classic:

importerror: attempted relative import with no known parent package

bbelderbos commented 3 years ago

Did you push any testing code, also how (from where) do you run the tests? That matters for the imports.

jeffwright13 commented 3 years ago

See, this is what I am talking about. I don't get why I am seeing that error in the /tests directory when trying to import the module I am trying to test.

$ tree
├── audio_program_generator
│   ├── audio_program_generator
│   │   ├── __init__.py
│   │   └── apg.py
│   └── tests
│       ├── __init__.py
│       └── test_apg.py
$ pwd
/Users/jeff/coding/audio_program_generator

$ python
Python 3.9.1 (default, Feb 14 2021, 19:42:58)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from audio_program_generator import apg
>>> dir(apg)
['AudioProgramGenerator', 'AudioSegment', 'BytesIO', 'Path', 'StringIO', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'docopt', 'gTTS', 'main', 'math', 'parse_textfile', 'pkg_resources', 're', 'tqdm']
>>>
>>> exit()

$ cd tests
$ pwd
/Users/jeff/coding/audio_program_generator/tests

$ python
Python 3.9.1 (default, Feb 14 2021, 19:42:58)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from audio_program_generator import apg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'audio_program_generator'
>>>
>>> from ..audio_program_generator import apg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: attempted relative import with no known parent package
>>>
bbelderbos commented 3 years ago

Check my tests for example: https://github.com/PyBites-Open-Source/git-stats

I run pytest in the root project folder and do absolute imports so in your case audio_program_generator.apg - that should work. If not push the branch and I will debug ...

jeffwright13 commented 3 years ago

Yes, running pytest from root folder works. Thanks!