Skip to content

unittest.Test: remove('*.osc'), md5.hexdigest, osc_modif_options.source - #8

Open
WK-GiHu wants to merge 2 commits into
jocelynj:masterfrom
WK-GiHu:unittest-remove('.osc'),-md5,-osc_modif(.)-input-parameters
Open

unittest.Test: remove('*.osc'), md5.hexdigest, osc_modif_options.source#8
WK-GiHu wants to merge 2 commits into
jocelynj:masterfrom
WK-GiHu:unittest-remove('.osc'),-md5,-osc_modif(.)-input-parameters

Conversation

@WK-GiHu

@WK-GiHu WK-GiHu commented Oct 23, 2016

Copy link
Copy Markdown
Contributor

Outsourced remove("tests/out/*.osc"):
Changed compare_files to use md5 hexdigest:
Adapted to new self.compare_files
Error Correction: osc_modif_options.source

Outsourced remove("tests/out/*.osc"):
Changed compare_files to use md5 hexdigest:
Adapted to new self.compare_files
Error Correction: osc_modif_options.source
Comment thread osc_modif/osc_modif.py

class osc_modif_options:
source = "tests/results/001.bbox.osc"
source = "tests/out/001.bbox.osc"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Error Correction:
The output of the previous bbox run goes to 'tests/out', therefore 'poly' run have to use the new generated file instead of a old in 'tests/results'.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good catch. This explains why the tests were working on my repository, but not on yours.

Comment thread osc_modif/osc_modif.py Outdated
osc_modif(None, osc_modif_options)

assert self.compare_files("tests/results/001.bbox.osc", "tests/out/001.bbox.osc")
assert self.compare_files('03a720a5b8c79f6c1bc486be5eb1e879', "tests/out/001.bbox.osc")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adapted to new self.compare_files
Parameter 1: A md5 hexdigest, which you can get with command line tool md5sum
Parameter 2: File whose data md5 hexdigest to be compared with give md5 hexdigest

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm wondering: won't it be easier to keep the original file to compare, instead of putting a md5sum ? It would make it very easy to compare the two files, and check where they differ in case of failure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is, because you don't answer my question regarding tests/results/*.
For me, the Name tests/results/* is misleading, expected unittest would write to this directory.
How can we be sure that the data in tests/results/* are error free?
Until now these files are only a copy from tests/out/*. Unittest therefore says nothing about valid datas. But regardless of this, I change compare_files(...) to compare_files('001.bbox.osc').

@jocelynj jocelynj Oct 27, 2016

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Oh, sorry about test/results/*. You are right that the name is misleading. This directory is intended to store the expected results of the various tests - and it is expected that files are a copy of tests/out/*, as tests are verifying that the python code is not broken.
Maybe we could rename this directory to tests/expected/* ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Think about this:
DE:Referenzdaten EN: reference data FR: Données de référence
Directory Name: 'tests/ref'
Summary:
tests - Input data
tests/out - Unittest output
tests/tmp-osmbin - osmbin unittest dbase
tests/tmp-osmosis - osmosis unittest dbase, if any
tests/ref - reference data to diff tests/out if needed

Thinking about your initial question: "...check where they differ in case of failure", using a hash in unitest does not prevent to make a diff.

Comment thread osc_modif/osc_modif.py Outdated
return filecmp.cmp(a, b)
def compare_files(self, aDigest, b):
from modules.helperLib import hash_file
return hash_file(b).cmp(aDigest)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed compare_files to use md5 hexdigest:

Comment thread osc_modif/osc_modif.py
else:
from modules.helperLib import remove
# remove old <outPath>*.osc files
remove( os.path.join(self.outPath, "*.osc") )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using Class variable to reduce data redundancy.
Outsourced remove("tests/out/*.osc"):

Changed `self.compare_files(...)` to use Filename instead of a hash.
Addapted `def compare_files(...)` to this.
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