def from_file(cls, file_): """ Construct a test class from a feature file. """ feature = Feature.from_file( file_, parser_class=TestGherkin, ) background = cls.make_background(feature.background) scenarios = [ cls.make_scenario(scenario, i + 1) for i, scenario in enumerate(feature.scenarios) ] before_feature, after_feature = \ CALLBACK_REGISTRY.before_after('feature') members = { 'feature': feature, 'background': background, 'before_feature': staticmethod(before_feature), 'after_feature': staticmethod(after_feature), } members.update({scenario.__name__: scenario for scenario in scenarios}) class_name = always_str(feature.name) return type(class_name, (cls, ), members)
def from_file(cls, file_): """ Construct a test class from a feature file. """ feature = Feature.from_file( file_, parser_class=TestGherkin, ) background = cls.make_background(feature.background) scenarios = [ cls.make_scenario(scenario, i + 1) for i, scenario in enumerate(feature.scenarios) ] before_feature, after_feature = \ CALLBACK_REGISTRY.before_after('feature') members = { 'feature': feature, 'background': background, 'before_feature': staticmethod(before_feature), 'after_feature': staticmethod(after_feature), } members.update({ scenario.__name__: scenario for scenario in scenarios }) class_name = always_str(feature.name) return type(class_name, (cls,), members)
def test_syntax_error_malformed_feature_from_file(): """Parsing a malformed feature in a filecauses a syntax error.""" with tempfile.NamedTemporaryFile() as feature_file: feature_file.write(b""" PARSE ERROR """) feature_file.flush() with assert_raises(AloeSyntaxError) as error: Feature.from_file(feature_file.name) # pylint:disable=line-too-long assert_equal(error.exception.msg, '\n'.join(( "Syntax error at: {filename}", "Parser errors:", "(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'PARSE ERROR'", )).format(filename=feature_file.name))
def test_syntax_error_malformed_feature_from_file(): """Parsing a malformed feature in a filecauses a syntax error.""" with tempfile.NamedTemporaryFile() as feature_file: feature_file.write(b""" PARSE ERROR """) feature_file.flush() with assert_raises(AloeSyntaxError) as error: Feature.from_file(feature_file.name) # pylint:disable=line-too-long assert_equal( error.exception.msg, '\n'.join(( "Syntax error at: {filename}", "Parser errors:", "(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'PARSE ERROR'", )).format(filename=feature_file.name))
def test_syntax_error_malformed_feature_from_file(): """Parsing a malformed feature in a filecauses a syntax error.""" with named_temporary_file() as feature_file: feature_file.write(b""" PARSE ERROR """) feature_file.close() with pytest.raises(AloeSyntaxError) as error: Feature.from_file(feature_file.name) # pylint:disable=line-too-long assert str(error.value) == "\n".join(( "Syntax error at: {filename}", "Parser errors:", "(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'PARSE ERROR' ({basename})", )).format(filename=feature_file.name, basename=os.path.basename(feature_file.name))