Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write tests for the app #31

Open
Namit2111 opened this issue Oct 15, 2024 · 11 comments
Open

Write tests for the app #31

Namit2111 opened this issue Oct 15, 2024 · 11 comments

Comments

@Namit2111
Copy link
Owner

Namit2111 commented Oct 15, 2024

We need tests for the whole app including backend and frontend that we can run on PR before merging them.

@Namit2111 Namit2111 added Enhancement 🚀 New feature or request help wanted Extra attention is needed hacktoberfest-accepted finished pr hacktoberfest labels Oct 15, 2024
@JustinhSE JustinhSE removed the hacktoberfest-accepted finished pr label Oct 16, 2024
@rajatkriplani
Copy link
Contributor

Please refer to my fork before going through this comment.
I'm getting some errors while running the test. And the error occurs during the import of app in your test_app.py and originates from the NLTK library when trying to read the 'bible-kjv.txt' file from the Gutenberg corpus.
Here's the relevant part of the traceback (from terminal):

backend/utils/utils.py:15: in <module>
    bible = gutenberg.raw('bible-kjv.txt')
myenv/lib/python3.12/site-packages/nltk/corpus/reader/api.py:219: in raw
    contents.append(fp.read())
myenv/lib/python3.12/site-packages/nltk/data.py:1139: in read
    chars = self._read(size)
myenv/lib/python3.12/site-packages/nltk/data.py:1425: in _read
    bytes = self.bytebuffer + new_bytes
E   TypeError: can't concat str to bytes

AND

[nltk_data] Downloading package gutenberg to /home/rajat/nltk_data...
[nltk_data]   Unzipping corpora/gutenberg.zip.
[nltk_data] [Errno 2] No such file or directory:
[nltk_data]     '/home/rajat/nltk_data/corpora/gutenberg.zip'
  • NLTK is attempting to load the gutenberg corpus. specifically it tries to load 'bible-kjv.txt' using gutenberg.raw('bible-kjv.txt').
  • TypeError occurs in NLTK's internal code it suggests a mismatch between expected data types (bytes vs. strings).
  • corrupted or missing data error messages indicate that the Gutenberg corpus might not be properly downloaded or accessible.
  • problem is that the code in utils/utils.py is executed immediately when the module is imported, even during testing.
  • when test_app.py imports app, which in turn imports utils.utils, the code that loads the corpus is executed, leading to the error.

fixes as follows:

  • Refactor utils/utils.py to avoid executing code at dodule level, move code that loads data or models into functions that are called when needed.
  • mock NLTK data tests, prevent it from attempting to download or access data during tests.
  • And ensure NLTK Data is properly installed.

@JustinhSE
Copy link
Collaborator

@Namit2111

@Namit2111
Copy link
Owner Author

hi @rajatkriplani which fork are you referring to can you please link it ?

@rajatkriplani
Copy link
Contributor

hi @rajatkriplani which fork are you referring to can you please link it ?

You can check the test_app.py here.

@Namit2111
Copy link
Owner Author

hi @rajatkriplani when are you available? ping me in discord

@JustinhSE JustinhSE removed Enhancement 🚀 New feature or request hacktoberfest help wanted Extra attention is needed labels Nov 8, 2024
@d-beloved
Copy link
Contributor

@JustinhSE @Namit2111 I think we should break this issue into two, for writing tests for the Frontend and another for Backend tests, then we can consolidate the check via a CI workflow

@JustinhSE
Copy link
Collaborator

@d-beloved sorry for the delayed response but feel free to open 2 issues for testing if you would like!

@JustinhSE
Copy link
Collaborator

@d-beloved do you want me to delete this and make a friont end and backend issue for this?

@d-beloved
Copy link
Contributor

d-beloved commented Dec 6, 2024 via email

@JustinhSE
Copy link
Collaborator

alright great!

@JustinhSE
Copy link
Collaborator

@Namit2111 this is your expertise as I am unsure what you would want in both issues. Let me know and I will write up both issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants