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

Fix block.py and add test for file block.py #25

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

Conversation

hashbangstudio
Copy link
Contributor

For Block class:
Add docstrings for functions in block.py
Fix references to attribute so all self.type not split between self.type and self.id
Add id property to maintain backwards compatibility
type and data are always integers and should be treated as such in __repr__
As __cmp__ no longer in Python 3 need to use functools.total_ordering which is in 2.7 and 3.*
https://docs.python.org/2/library/functools.html#functools.total_ordering
https://docs.python.org/3/library/functools.html#functools.total_ordering
Define __eq__ and __lt__ and others are created automatically

For blockType enumeration:
Move to back ported IntEnum as allows direct integer comparison
https://pypi.python.org/pypi/enum34
https://docs.python.org/3/library/enum.html#intenum

Add test_block.py:
A unit test module to test the block file

For Block class:
  Add docstrings for functions in block.py
  Fix references to attribute so all self.type not split between self.type and self.id
  Add id property to maintain backwards compatibility
  type and data are always integers and should be treated as such in __repr__
  As __cmp__ no longer in Python 3 need to use functools.total_ordering which is in 2.7 and 3.*
  https://docs.python.org/2/library/functools.html#functools.total_ordering
  https://docs.python.org/3/library/functools.html#functools.total_ordering
  Define __eq__ and __lt__ and others are created automatically

For blockType enumeration:
  Move to back ported IntEnum as allows direct integer comparison
  https://pypi.python.org/pypi/enum34
  https://docs.python.org/3/library/enum.html#intenum

Add test_block.py:
  A unit test module to test the block file
@doismellburning
Copy link
Member

Why are blocks orderable? Does some odd bit of the API depend on this? :s

@hashbangstudio
Copy link
Contributor Author

Don't have to orderable as far as I am aware but they had been defined as such with __cmp__ in the original API and thought safest to replicate the original behaviour. Could just define __eq__ and __ne__ if people prefer.

@hashbangstudio
Copy link
Contributor Author

Until enum34 package defined in Travis, build will fail see #23 as enum won't exist.

@doismellburning
Copy link
Member

I don't think nonsensical orderings are helpful - will look to see if it's actually used anywhere (I hope not...)

for index, attr in enumerate(b):
self.assertEqual(attr, idAndData[index])

def testBlockConstants(self):
Copy link
Member

Choose a reason for hiding this comment

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

I may be alone here, but I'm unconvinced by the value of testing constants - persuade me...?

@hashbangstudio
Copy link
Contributor Author

Testing that the name exists as well as the value in this case with enum.
Thinking was in case a line in the blockType definition gets deleted/altered, or name has been changed accidentally from e.g. global find and replace.
In both cases enum is still valid to interpreter, but one element of enum that would be used in code won't exist.
Should always be caught on commit but have seen mistakes happen or all modifications committed unintentionally.
Additionally are checking the aliasing of water and lava to flowing variants.
Easy enough to lose if unwanted.

block.data = The variant of the type of block.
For example the colour of wool or the orientation of stairs
The default type for blocks is dirt
"""
Copy link
Member

Choose a reason for hiding this comment

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

Why the indentation change?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is unnecessary, can you keep the indentation of docstrings to one level in line with PEP 257 please.

Copy link
Member

Choose a reason for hiding this comment

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

@ghickman Got the pep8/flake8 skillz to add this to tests so you don't need to keep hand-PEPing? ;P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unintentional will alter

Copy link
Member

Choose a reason for hiding this comment

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

@hashbangstudio – Thanks!

This should hopefully mean that build will pass with enum dependency met
def __eq__(self, rhs):
"""
Equality override
Two blocks are equal only if their hashes are equal
Copy link
Member

Choose a reason for hiding this comment

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

Except that's only true in this case where hash doesn't collide, and not generally true - would you mind making a proper __eq__ please?

Fix __eq__ so block only equal if all attributes equal
Fix apostrophe usage
Move to PEP8 lowercase_name method names
Move test of water and lava aliases out to separate test
Add function (self): that was left missing
blockType changed to BlockType
Change functions and variables to lower_case


class blockType(Enum):
Copy link
Member

Choose a reason for hiding this comment

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

I think this changes a bit of the API we don't want to change, but we aren't testing thoroughly enough :s

@hashbangstudio
Copy link
Contributor Author

It will need to be changed for PEP8 naming and can't see where it is used in the rest of the API at the moment, unless I am just not seeing it. Can drop it from PR if it is used somewhere.

Remove unittest style file
Add py.test style file
Variable missed in conversion to PEP8 standards
Change variable name to avoid confusion between withData(data)
  and the Block(type, data) created instances
Add comparison test using eval(repr())
Change to comparing against a constant string
@doismellburning
Copy link
Member

So, sorry about this, but I had to revert a bunch of other changes to fix compatibility breakages they introduced. Are you ok to fix the merge conflicts here, or would you like a hand? Cheers, apologies!

@hashbangstudio
Copy link
Contributor Author

Will have a look to see if can fix conflicts over the weekend, if not will let you know

@doismellburning
Copy link
Member

Awesome, thanks, sorry again!

@doismellburning
Copy link
Member

<3 thanks for the fixes!

For example grass, sand, dirt or wool
block.data = The variant of the type of block.
For example the colour of wool or the orientation of stairs
The default type for blocks is dirt
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I'm a bit too keen on building obsidian houses, but I'm personally very wary about introducing defaults for what is a somewhat arbitrary choice...

@hashbangstudio
Copy link
Contributor Author

Agree is arbitrary, was left in from previous API refactoring. Have removed default assignment.

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.

4 participants