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

BeautifulSoup logic in separate file #56

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

MaxxxZu
Copy link
Collaborator

@MaxxxZu MaxxxZu commented Apr 27, 2020

No description provided.

@MaxxxZu MaxxxZu requested a review from dkultasev April 27, 2020 18:46
@MaxxxZu MaxxxZu linked an issue Apr 27, 2020 that may be closed by this pull request
@MaxxxZu MaxxxZu self-assigned this Apr 27, 2020
smarsy/bs_helper.py Outdated Show resolved Hide resolved
tests/test_bs_helper.py Outdated Show resolved Hide resolved
tests/test_bs_helper.py Outdated Show resolved Hide resolved
tests/test_bs_helper.py Outdated Show resolved Hide resolved
tests/test_bs_helper.py Outdated Show resolved Hide resolved
tests/test_bs_helper.py Outdated Show resolved Hide resolved
if no object is found for the given selector
"""
for arg in args:
selectedElems = html.select_one(arg)
Copy link
Owner

Choose a reason for hiding this comment

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

won't it always take the last output of the select_one ? It's not adding, for every iteration it re-assigns selectedElems with the new value. No? or is it expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is what is expected. Each new iteration overrides a variable selectedElems

Copy link
Owner

Choose a reason for hiding this comment

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

then I don't get it, does it supposed to return:

  • all objects for all found selectors?
  • the last found object?
  • the first found object?
  • any object?
  • is it expected to be some kind of chaining action, when the result of the previous iteration is used in the next one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

then I don't get it, does it supposed to return:

we take the object, apply the method select_one with selector 1 to it, then apply the method select_one with selector 2 to the received object, then apply the method select_one with the selector X to the received object and return the object or False

Copy link
Owner

Choose a reason for hiding this comment

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

could you please provide real example from smarsy website? expected call with expected result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From issue#51
<TD valign=top align="left" width="120"><img src="https://smarsy.ua/images/mypage/parent_1.png"></TD>
We must find td with valign=top and in received object find img[src]

Copy link
Owner

Choose a reason for hiding this comment

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

and what would be the function call for that html?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

html.select_one([valign=top]).select_one('img[src]')

Copy link
Owner

Choose a reason for hiding this comment

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

will it work? Additionally here you are passing single value parameter, but in your function you are expecting array. Please provide an example with array

self.assertEqual(actual, 'some text')

def test_bs_safe_select_return_expected_text_with_many_selectors(self):
selector1, selector2, selector3 = 'some_tag1', 'some_tag2', 'some_tag3'
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand this test. It works with any selector values and with any quantity of them. What's the purpose of it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Owner

Choose a reason for hiding this comment

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

not sure what was done for this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I refactored this test

tests/test_bs_helper.py Outdated Show resolved Hide resolved
self.mocked_soup.get.return_value = 'some text'
actual = self.source_page.bs_safe_get(self.mocked_soup,
'some attribute')
self.assertEqual(actual, 'some text')
Copy link
Owner

Choose a reason for hiding this comment

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

as you are testing the fact that you are getting the output of the get function, then you should use self.mocked_soup.get.return_value instead of hardcoding some text in the assert

Copy link
Owner

Choose a reason for hiding this comment

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

this is not done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you saw latest commit?
def test_bs_safe_get_return_expected_text(self):
actual = self.source_page.bs_safe_get(self.mocked_soup, self.expected_attribute)
self.assertEqual(actual, self.expected_text)

tests/test_bs_helper.py Outdated Show resolved Hide resolved

def test_bs_safe_select_return_expected_text_with_many_selectors(self):
select_one = None
for select_one_value in self.select_one_values:
Copy link
Owner

Choose a reason for hiding this comment

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

the test is re-producing the same logic as in the function that is not good. This test is bad, but before answering what exactly is bad you need to answer the question posted under this function's source code.

tests/test_bs_helper.py Outdated Show resolved Hide resolved
tests/test_bs_helper.py Outdated Show resolved Hide resolved
@dkultasev dkultasev force-pushed the issue-55-Move_out_Be_logic_to_sep_PR branch from fe9959d to 06a5df1 Compare July 3, 2020 06:33
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.

Move out BeautifulSoup logic to separate PR
2 participants