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

Changes made for table iteration #26

Merged
merged 7 commits into from
Nov 21, 2024
Merged

Changes made for table iteration #26

merged 7 commits into from
Nov 21, 2024

Conversation

rabelmervin
Copy link
Contributor

Description

Initially the tables used a simple string method of matching. Now its updated to iteration method that iterates over the tables. previous error with the formatting also rectified.

@rabelmervin
Copy link
Contributor Author

hi @tedivm black formatting issue fixed ! please review it

@tedivm
Copy link
Owner

tedivm commented Nov 19, 2024

We still need tests for the new functionality.

@tedivm
Copy link
Owner

tedivm commented Nov 19, 2024

For testing basically copy the test_graph_with_exclusion and test_graph_with_inclusion functions (https://github.com/tedivm/paracelsus/blob/main/tests/test_cli.py#L42) so you have test_graph_with_exclusion_regex and test_graph_with_inclusion_regex.

Then tweak the command line arguments to use some regex patterns, before finally testing that the appropriate tables are present (or not present, as the case may be).

@rabelmervin
Copy link
Contributor Author

rabelmervin commented Nov 19, 2024

Sure @tedivm thanks for your information 😊

@rabelmervin
Copy link
Contributor Author

Hi @tedivm test was successfully passed can i make a pr now ?

Screenshot (6)

@tedivm
Copy link
Owner

tedivm commented Nov 20, 2024

Just push the new tests to this branch and this branch will automatically update and I can review.

Copy link
Owner

@tedivm tedivm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I provided some comments to help improve the tests.

Comment on lines 165 to 168
assert result.exit_code == 0
assert "regular_table {" not in result.stdout
assert "first_test {" in result.stdout
assert "second{" not in result.stdout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't make sense- I don't know where these strings are coming from. The goal here is to test that the proper columns exist, but the excluded ones do not.

In this case we have three tables- comments, users, and posts. Since we're trying to include the pattern ^com.* we expect the comments table to be in the diagram but not the other two.

assert "comments {" in result.stdout
assert "users {" not in result.stdout
assert "post {" not in result.stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise @tedivm I'll make changes !

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! I appreciate you taking this on!

Comment on lines 186 to 188
assert "regular_table {" in result.stdout
assert "first {" not in result.stdout
assert "second {" in result.stdout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we have three tables- comments, users, and posts. Since we're trying to exclude the pattern ^pos.* we expect the comments and users table to be in the diagram but not the posts one.

assert "comments {" in result.stdout
assert "users {" in result.stdout
assert "post {" not in result.stdout

@rabelmervin
Copy link
Contributor Author

rabelmervin commented Nov 20, 2024

hi @tedivm I have changed that useless strings, used regex pattern and tests passed. could you please tell me if there is any mistakes ?

Comment on lines 162 to 174
"^com.*",
"comments",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should remain ^com.*, otherwise you aren't testing the regex.

Comment on lines 182 to 194
"pos.*",
"^pos*",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this should be ^pos.*

@tedivm
Copy link
Owner

tedivm commented Nov 20, 2024

It looks like when you updated the tests you removed the regex from them, but the whole point of these tests is to make sure the regex is actually used and works as expected.

Comment on lines 147 to 159
from click.testing import CliRunner
from paracelsus.cli import app

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class Comments(Base):
__tablename__ = "comments"
id = Column(Integer, primary_key=True)
text = Column(String)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this- use the existing test database, it works perfectly for this use case.

Also imports should never be here, always at the top of the file.

@rabelmervin
Copy link
Contributor Author

Sorry @tedivm , Now i made changes can you please review it ?

@tedivm
Copy link
Owner

tedivm commented Nov 21, 2024

Okay, so the tests themselves look good now. They're testing what we want to test.

However, it looks like one of the tests is failing.

    def test_graph_with_inclusion_regex(package_path: Path):
        result = runner.invoke(
            app,
            [
                "graph",
                "example.base:Base",
                "--import-module",
                "example.models",
                "--python-dir",
                str(package_path),
                "--include-tables",
                "^com.*",
            ],
        )
        assert result.exit_code == 0
>       assert "comments {" in result.stdout
E       AssertionError: assert 'comments {' in 'erDiagram\n\n'
E        +  where 'erDiagram\n\n' = <Result okay>.stdout

tests/test_cli.py:162: AssertionError

This error is showing that the comments table isn't in the diagram, even though we expect it to be. You don't need to change the tests to fix this, but look at the code itself with the changes. I'm going to put some inline comments to show what I think is happening.

@tedivm
Copy link
Owner

tedivm commented Nov 21, 2024

Github won't let me make the comment inline, but on line 97 of the paracelsus/graph.py file you likely want to change return include_tables to return included.

On line 92 you should also change include_tables to included.

I think with those two changes tests will pass.

@tedivm
Copy link
Owner

tedivm commented Nov 21, 2024

Actually I was wrong about line 92, it's probably just line 97 that needs the change.

@rabelmervin
Copy link
Contributor Author

Good morning @tedivm, I have made changes include_tables to included

@tedivm
Copy link
Owner

tedivm commented Nov 21, 2024

It all works now! Thank you so much for contributing and working through the review process.

@tedivm tedivm merged commit d9df811 into tedivm:main Nov 21, 2024
9 checks passed
@rabelmervin
Copy link
Contributor Author

Thank you @tedivm for merging my PR and supporting me during the process. I really value the collaboration and would love to stay connected. Looking forward to learning from you and contributing more in the future.

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

Successfully merging this pull request may close these issues.

2 participants