def testExpectedWarnings(self): msg = '' # compare test files (.input and .expected for each) # N.B. in some cases, python 2 and python 3 will have different output! for fn in pathmap.all_files(os.path.join('collections', 'warn_err')): if fn.endswith('.input'): frag = fn[:-len('.input')] efn = frag + '.expected' # check for a python version-specific file, like 'foo.expected-py3' current_python_version = (sys.version_info > (3, 0)) and 'py3' or 'py2' versioned_efn = '{f}-{v}'.format(f=efn, v=current_python_version) if os.path.exists(versioned_efn): efn = versioned_efn if os.path.exists(efn): inp = testing_read_json(fn) aa = validate_collection(inp) errors = aa[0] exp = testing_read_json(efn) if errors != exp: ofn = frag + '.output' testing_write_json(errors, ofn) msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(o=ofn, e=efn) self.assertEqual(exp, errors, msg) else: _LOG.warn('Expected output file "{f}" not found'.format(f=efn))
def testExpectedWarnings(self): msg = '' # compare test files (.input and .expected for each) # TODO: Add these files for amendments! # N.B. in some cases, python 2 and python 3 will have different output! for fn in pathmap.all_files(os.path.join('amendments', 'warn_err')): if fn.endswith('.input'): frag = fn[:-len('.input')] efn = frag + '.expected' # check for a python version-specific file, like 'foo.expected-py3' current_python_version = (sys.version_info > (3, 0)) and 'py3' or 'py2' versioned_efn = '{f}-{v}'.format(f=efn, v=current_python_version) if os.path.exists(versioned_efn): efn = versioned_efn if os.path.exists(efn): inp = testing_read_json(fn) aa = validate_amendment(inp) errors = aa[0] exp = testing_read_json(efn) if errors != exp: ofn = frag + '.output' testing_write_json(errors, ofn) msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(o=ofn, e=efn) self.assertEqual(exp, errors, msg) else: _LOG.warn('Expected output file "{f}" not found'.format(f=efn))
def testInvalidFilesFail(self): msg = '' for fn in pathmap.all_files(os.path.join('nexson', 'lacking_otus')): if fn.endswith('.input'): frag = fn[:-len('.input')] inp = read_json(fn) aa = validate_nexson(inp) annot = aa[0] if len(annot.errors) == 0: ofn = pathmap.nexson_source_path(frag + '.output') ew_dict = annot.get_err_warn_summary_dict() write_json(ew_dict, ofn) msg = "Failed to reject file. See {o}".format(o=str(msg)) self.assertTrue(False, msg)
def testOldExpectedWarnings(self): msg = '' for fn in pathmap.all_files(os.path.join('nexson', 'old-tests')): if fn.endswith('.input'): frag = fn[:-len('.input')] efn = frag + '.expected' if os.path.exists(efn): inp = testing_read_json(fn) aa = validate_nexson(inp) annot = aa[0] ew_dict = annot.get_err_warn_summary_dict() ew_dict = testing_through_json(ew_dict) exp = testing_read_json(efn) if not testing_dict_eq(ew_dict, exp): ofn = frag + '.output' testing_write_json(ew_dict, ofn) msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format(o=ofn, e=efn) self.assertDictEqual(exp, ew_dict, msg) else: _LOG.warn('Expected output file "{f}" not found'.format(f=efn))
def testOldExpectedWarnings(self): msg = '' for fn in pathmap.all_files(os.path.join('nexson', 'old-tests')): if fn.endswith('.input'): frag = fn[:-len('.input')] efn = frag + '.expected' if os.path.exists(efn): inp = testing_read_json(fn) aa = validate_nexson(inp) annot = aa[0] ew_dict = annot.get_err_warn_summary_dict() ew_dict = testing_through_json(ew_dict) exp = testing_read_json(efn) if not testing_dict_eq(ew_dict, exp): ofn = frag + '.output' testing_write_json(ew_dict, ofn) msg = "Validation failed to produce expected outcome. Compare {o} and {e}".format( o=ofn, e=efn) self.assertDictEqual(exp, ew_dict, msg) else: _LOG.warn( 'Expected output file "{f}" not found'.format(f=efn))