-
Notifications
You must be signed in to change notification settings - Fork 4
unittest.Test: remove('*.osc'), md5.hexdigest, osc_modif_options.source #8
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
## along with this program. If not, see <http://www.gnu.org/licenses/>. ## | ||
## ## | ||
########################################################################### | ||
## Modified: WK-GiHu osc_modif_101.py | ||
|
||
import sys, re, urllib, time | ||
from modules import OsmSax | ||
|
@@ -102,7 +103,10 @@ def init(self): | |
import unittest | ||
|
||
class Test(unittest.TestCase): | ||
|
||
import os | ||
rootPath = "tests" | ||
outPath = os.path.join(rootPath, "out") | ||
|
||
def setUp(self): | ||
import os | ||
import shutil | ||
|
@@ -111,8 +115,14 @@ def setUp(self): | |
OsmBin.InitFolder("tmp-osmbin/") | ||
self.osmbin = OsmBin.OsmBin("tmp-osmbin/", "w") | ||
self.osmbin.Import("tests/000.osm") | ||
if not os.path.exists("tests/out"): | ||
os.makedirs("tests/out") | ||
|
||
if not os.path.exists( self.outPath ): | ||
os.makedirs( self.outPath ) | ||
else: | ||
from modules.helperLib import remove | ||
# remove old <outPath>*.osc files | ||
remove( os.path.join(self.outPath, "*.osc") ) | ||
|
||
del self.osmbin | ||
|
||
def tearDown(self): | ||
|
@@ -122,9 +132,9 @@ def tearDown(self): | |
del self.osmbin | ||
shutil.rmtree("tmp-osmbin/") | ||
|
||
def compare_files(self, a, b): | ||
import filecmp | ||
return filecmp.cmp(a, b) | ||
def compare_files(self, aDigest, b): | ||
from modules.helperLib import hash_file | ||
return hash_file(b).cmp(aDigest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed compare_files to use md5 hexdigest: |
||
|
||
def test(self): | ||
class osc_modif_options: | ||
|
@@ -136,14 +146,14 @@ class osc_modif_options: | |
osmbin_path = "tmp-osmbin/" | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adapted to new self.compare_files There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is, because you don't answer my question regarding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think about this: 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. |
||
|
||
class osc_modif_options: | ||
source = "tests/results/001.bbox.osc" | ||
source = "tests/out/001.bbox.osc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error Correction: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
dest = "tests/out/001.poly.osc" | ||
poly = "tests/polygon.poly" | ||
position_only = False | ||
osmbin_path = "tmp-osmbin/" | ||
osc_modif(None, osc_modif_options) | ||
|
||
assert self.compare_files("tests/results/001.poly.osc", "tests/out/001.poly.osc") | ||
assert self.compare_files('e83aa99d6f72111d2a885b4dbd9e607a', "tests/out/001.poly.osc") |
There was a problem hiding this comment.
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"):