From 78850c45e1d099a18bff4b039473db31f7cab11c Mon Sep 17 00:00:00 2001 From: Edwin Lee Date: Sat, 24 Nov 2018 10:32:20 -0600 Subject: [PATCH] Remove html_data separate file --- epregressions/builds/visualstudio.py | 3 +- epregressions/diffs/html_data.py | 66 ------------------ epregressions/diffs/table_diff.py | 69 ++++++++++++++++--- epregressions/tests/builds/test_base.py | 2 +- epregressions/tests/builds/test_install.py | 2 +- epregressions/tests/builds/test_makefile.py | 2 +- .../tests/builds/test_visualstudio.py | 39 +++++++++-- 7 files changed, 99 insertions(+), 84 deletions(-) delete mode 100755 epregressions/diffs/html_data.py diff --git a/epregressions/builds/visualstudio.py b/epregressions/builds/visualstudio.py index b564b05..6ad15a3 100644 --- a/epregressions/builds/visualstudio.py +++ b/epregressions/builds/visualstudio.py @@ -74,7 +74,8 @@ def verify(self): ["Case %s Products Directory Exists? ", products_dir, exists] ) build_mode_folder = 'Release' - release_folder_exists = os.path.join(self.build_directory, 'Products', build_mode_folder) + release_folder = os.path.join(self.build_directory, 'Products', build_mode_folder) + release_folder_exists = os.path.exists(release_folder) if release_folder_exists: self.set_build_mode(debug=False) else: diff --git a/epregressions/diffs/html_data.py b/epregressions/diffs/html_data.py deleted file mode 100755 index f7b5675..0000000 --- a/epregressions/diffs/html_data.py +++ /dev/null @@ -1,66 +0,0 @@ -"""html data to be used by other modules""" - -# Copyright (C) 2009 Santosh Philip -# This file is part of tablediff. -# -# tablediff is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# tablediff is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with tablediff. If not, see . -# VERSION: 1.0 - - -titlecss = """ -%s - - -""" - -titlehtml = """ - - - %s - - - - - - -""" - - -thecss = """td.big { - background-color: #FF969D; -} - -td.small { - background-color: #FFBE84; -} - -td.equal { - background-color: #CBFFFF; -} - -td.table_size_error { - background-color: #FCFF97; -} -.big { - background-color: #FF969D; -} - -.small { - background-color: #FFBE84; -} - -""" diff --git a/epregressions/diffs/table_diff.py b/epregressions/diffs/table_diff.py index 8ebec8b..ac518e3 100755 --- a/epregressions/diffs/table_diff.py +++ b/epregressions/diffs/table_diff.py @@ -41,13 +41,58 @@ import os.path from bs4 import BeautifulSoup, NavigableString, Tag -from epregressions.diffs import html_data help_message = __doc__ path = os.path.dirname(__file__) script_dir = os.path.abspath(path) +titlecss = """ +%s + + +""" + +titlehtml = """ + + + %s + + + + + + +""" + +thecss = """td.big { + background-color: #FF969D; +} + +td.small { + background-color: #FFBE84; +} + +td.equal { + background-color: #CBFFFF; +} + +td.table_size_error { + background-color: #FCFF97; +} +.big { + background-color: #FF969D; +} + +.small { + background-color: #FFBE84; +} + +""" + class Usage(Exception): """ usage """ @@ -57,7 +102,7 @@ def __init__(self, msg): def thresh_abs_rel_diff(abs_thresh, rel_thresh, x, y): - if (x == y): + if x == y: return (0, 0, 'equal') try: fx = float(x) @@ -320,13 +365,16 @@ def table_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file comparingthis = 'Comparing
%s
vs
%s

' % (inputfile1, inputfile2) # Error soup - err_soup = BeautifulSoup(html_data.titlecss % (pagetitle + ' -- summary', html_data.thecss,), features='html.parser') + err_soup = BeautifulSoup(titlecss % (pagetitle + ' -- summary', thecss,), + features='html.parser') # Abs diff soup - abs_diff_soup = BeautifulSoup(html_data.titlecss % (pagetitle + ' -- absolute differences', html_data.thecss,), features='html.parser') + abs_diff_soup = BeautifulSoup(titlecss % (pagetitle + ' -- absolute differences', thecss,), + features='html.parser') # Rel diff soup - rel_diff_soup = BeautifulSoup(html_data.titlecss % (pagetitle + ' -- relative differences', html_data.thecss,), features='html.parser') + rel_diff_soup = BeautifulSoup(titlecss % (pagetitle + ' -- relative differences', thecss,), + features='html.parser') # Make error table tabletag = Tag(err_soup, name='table', attrs=[('border', '1')]) @@ -449,14 +497,16 @@ def table_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file for h in horder1: if h not in horder2: continue - abs_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [(x_y_z[0],x_y_z[2]) for x_y_z in diff_dict[h]] + abs_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [ + (x_y_z[0], x_y_z[2]) for x_y_z in diff_dict[h]] hdict2soup(abs_diff_soup, uheading1, count_of_tables, abs_diff_dict.copy(), h_thresh_dict, horder1) rel_diff_dict = {} for h in horder1: if h not in horder2: continue - rel_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [(x_y_z[1],x_y_z[2]) for x_y_z in diff_dict[h]] + rel_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [ + (x_y_z[1], x_y_z[2]) for x_y_z in diff_dict[h]] hdict2soup(rel_diff_soup, uheading1, count_of_tables, rel_diff_dict.copy(), h_thresh_dict, horder1) count_of_tables_diff += 1 @@ -487,8 +537,9 @@ def table_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file "Case,TableCount,BigDiffCount,SmallDiffCount,EqualCount,StringDiffCount,SizeErrorCount,NotIn1Count,NotIn2Count\n") with open(summary_file, 'a') as summarize: summarize.write("%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % ( - case_name, count_of_tables, count_of_big_diff, count_of_small_diff, count_of_equal, count_of_string_diff, - count_of_size_error, count_of_not_in_1, count_of_not_in_2)) + case_name, count_of_tables, count_of_big_diff, count_of_small_diff, count_of_equal, + count_of_string_diff, + count_of_size_error, count_of_not_in_1, count_of_not_in_2)) return ('', count_of_tables, count_of_big_diff, count_of_small_diff, count_of_equal, count_of_string_diff, count_of_size_error, count_of_not_in_1, count_of_not_in_2) diff --git a/epregressions/tests/builds/test_base.py b/epregressions/tests/builds/test_base.py index b22d7d3..f2437db 100644 --- a/epregressions/tests/builds/test_base.py +++ b/epregressions/tests/builds/test_base.py @@ -3,7 +3,7 @@ from epregressions.builds.base import BaseBuildDirectoryStructure -class TestBaseWorkflowMethods(unittest.TestCase): +class TestBaseBuildMethods(unittest.TestCase): def setUp(self): self.base_build = BaseBuildDirectoryStructure() diff --git a/epregressions/tests/builds/test_install.py b/epregressions/tests/builds/test_install.py index 6451700..7f333bf 100644 --- a/epregressions/tests/builds/test_install.py +++ b/epregressions/tests/builds/test_install.py @@ -4,7 +4,7 @@ from epregressions.builds.install import EPlusInstallDirectory -class TestBaseWorkflowMethods(unittest.TestCase): +class TestEPInstallBuildMethods(unittest.TestCase): def setUp(self): self.build = EPlusInstallDirectory() diff --git a/epregressions/tests/builds/test_makefile.py b/epregressions/tests/builds/test_makefile.py index 54282d2..7b04c3a 100644 --- a/epregressions/tests/builds/test_makefile.py +++ b/epregressions/tests/builds/test_makefile.py @@ -5,7 +5,7 @@ from epregressions.builds.makefile import CMakeCacheMakeFileBuildDirectory -class TestBaseWorkflowMethods(unittest.TestCase): +class TestMakefileBuildMethods(unittest.TestCase): def setUp(self): self.build = CMakeCacheMakeFileBuildDirectory() diff --git a/epregressions/tests/builds/test_visualstudio.py b/epregressions/tests/builds/test_visualstudio.py index 6451700..85a9915 100644 --- a/epregressions/tests/builds/test_visualstudio.py +++ b/epregressions/tests/builds/test_visualstudio.py @@ -1,29 +1,57 @@ +import os import tempfile import unittest -from epregressions.builds.install import EPlusInstallDirectory +from epregressions.builds.visualstudio import CMakeCacheVisualStudioBuildDirectory -class TestBaseWorkflowMethods(unittest.TestCase): +class TestVisualStudioBuildMethods(unittest.TestCase): def setUp(self): - self.build = EPlusInstallDirectory() + self.build = CMakeCacheVisualStudioBuildDirectory() self.run_dir = tempfile.mkdtemp() + self.dummy_source_dir = '/dummy/source/dir' + + def set_cache_file(self): + with open(os.path.join(self.run_dir, 'CMakeCache.txt'), 'w') as f: + f.write('HEY\n') + f.write('CMAKE_HOME_DIRECTORY:INTERNAL=%s\n' % self.dummy_source_dir) + f.write('HEY AGAIN\n') def test_set_build_directory_does_not_exist(self): self.build.set_build_directory('hello') self.assertIn('unknown', self.build.source_directory) - def test_set_build_directory_does_exist(self): + def test_set_build_directory_does_exist_but_no_cache(self): + with self.assertRaises(Exception): + self.build.set_build_directory(self.run_dir) + + def test_set_build_directory_does_exist_but_empty_cache(self): + with open(os.path.join(self.run_dir, 'CMakeCache.txt'), 'w') as f: + f.write('\n') + with self.assertRaises(Exception): + self.build.set_build_directory(self.run_dir) + + def test_set_build_directory_and_has_cache(self): + self.set_cache_file() self.build.set_build_directory(self.run_dir) - self.assertEqual(self.run_dir, self.build.source_directory) + self.assertEqual(self.dummy_source_dir, self.build.source_directory) def test_verify_before_setting_build_directory(self): with self.assertRaises(Exception): self.build.verify() def test_verify_but_nothing_exists(self): + self.set_cache_file() + self.build.set_build_directory(self.run_dir) + check = self.build.verify() + self.assertIsInstance(check, list) + self.assertGreaterEqual(len(check), 4) # there should be some errors + + def test_verify_with_release_folder(self): + self.set_cache_file() self.build.set_build_directory(self.run_dir) + os.makedirs(os.path.join(self.run_dir, 'Products', 'Release')) check = self.build.verify() self.assertIsInstance(check, list) self.assertGreaterEqual(len(check), 4) # there should be some errors @@ -33,6 +61,7 @@ def test_get_build_tree_before_setting_build_directory(self): self.build.get_build_tree() def test_get_build_tree(self): + self.set_cache_file() self.build.set_build_directory(self.run_dir) tree = self.build.get_build_tree() self.assertIsInstance(tree, dict)