Skip to content
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

Jython 2.7 #1079

Open
HoudayerPierre opened this issue Jan 6, 2023 · 3 comments
Open

Jython 2.7 #1079

HoudayerPierre opened this issue Jan 6, 2023 · 3 comments

Comments

@HoudayerPierre
Copy link

HoudayerPierre commented Jan 6, 2023

Hello,

I have something strange with Jython 2.7 (using sikuli IDE 2.0.5). Is it not possible to run behave with in Jython ?

import sys
# fix "import parse" error
sys.path.insert(0, 'Lib/parse_type')

from behave import __main__ as behave_main

arguments = ["sbs_demo.sikuli/features/test.feature"]

behave_main.main(arguments)

will result with :

[error] script [ sikulitemp-6153508322918227856 ] stopped with error in line 5
[error] ValueError ( unichr() arg is a lone surrogate in range (0xD800, 0xDFFF) (Jython UTF-16 encoding) )
[error] --- Traceback --- error source first
line: module ( function ) statement 
115: junit (  _compile_invalid_re )     "%s-%s" % (unichr(low), unichr(high))
122: junit (  <module> )     _invalid_re = _compile_invalid_re()
17: configuration (  <module> )     from behave.reporter.junit import JUnitReporter
8: __main__ (  <module> )     from behave.configuration import Configuration
5: main (  <module> )     from behave import __main__ as behave_main
[error] --- Traceback --- end --------------

image

@jenisys
Copy link
Member

jenisys commented Jan 15, 2023

Smells like a Unicode encoding issue, maybe of your script file from above.
Try to use „UTF-8“ and see if the problem vanishes.
In addition, it may be useful to place an encoding hint in the script file, like:

# -*- coding: UTF-8 -*-
# — HINT: Same as above from here on.
import sys

HINT: But the file needs to have also this encoding.

@HoudayerPierre
Copy link
Author

Hello, adding # -*- coding: UTF-8 -*- at the beginning of the file did not change the error.

For now, this is a very bad idea, as a workaround it seems to works. I replaced the file in Lib/behave/reporter/junit.py with this modifications in the funtion _compile_invalid_re() line 101 :

def _compile_invalid_re():
    # http://stackoverflow.com/questions/1707890/fast-way-to-filter-illegal-xml-unicode-chars-in-python
    illegal_unichrs = [
        (0x00, 0x08), (0x0B, 0x1F), (0x7F, 0x84), (0x86, 0x9F),
        (0xD800, 0xDFFF), (0xFDD0, 0xFDDF), (0xFFFE, 0xFFFF),
        (0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF), (0x3FFFE, 0x3FFFF),
        (0x4FFFE, 0x4FFFF), (0x5FFFE, 0x5FFFF), (0x6FFFE, 0x6FFFF),
        (0x7FFFE, 0x7FFFF), (0x8FFFE, 0x8FFFF), (0x9FFFE, 0x9FFFF),
        (0xAFFFE, 0xAFFFF), (0xBFFFE, 0xBFFFF), (0xCFFFE, 0xCFFFF),
        (0xDFFFE, 0xDFFFF), (0xEFFFE, 0xEFFFF), (0xFFFFE, 0xFFFFF),
        (0x10FFFE, 0x10FFFF),
    ]
############################################################################################################################
#This version of the function excludes the surrogate range from the list of invalid characters, which should resolve the "ValueError" error.
    illegal_ranges = [
        u"%s-%s" % (unichr(low), unichr(high))
        for (low, high) in illegal_unichrs
        if low < sys.maxunicode and (low < 0xD800 or high > 0xDFFF)]
############################################################################################################################
#    illegal_ranges = [
#        "%s-%s" % (unichr(low), unichr(high))
#        for (low, high) in illegal_unichrs
#        if low < sys.maxunicode]

    return re.compile(u'[%s]' % u''.join(illegal_ranges))

@HoudayerPierre
Copy link
Author

Hello, I have run all tutorials in behave.github.io/behave.example with this workaround.

Run all tutorials :

12 features passed, 0 failed, 0 skipped
24 scenarios passed, 0 failed, 0 skipped
75 steps passed, 0 failed, 0 skipped, 0 undefined

Run Data Types and User-defined Types
This is the only one not able to passed without editing but it's probably because it's Jython 2.7.3 and this syntax is Python 3+ right ?
@when(u'I meet {persons:Person+}')
@when(u'I paint with{:slurp_space}{colors:Color*}')
@when('attacked by {:a_?}{opponent}')
because when i removed +, *, ? there is no syntaxe errors

Failing scenarios:
  behave_tutorial.sikuli\datatype.features\choice.feature:13  Bad Case -- Undefined step definition for "diamonds"

4 features passed, 1 failed, 0 skipped
14 scenarios passed, 1 failed, 0 skipped
41 steps passed, 0 failed, 0 skipped, 1 undefined

Run Step Matchers:

5 features passed, 0 failed, 0 skipped
11 scenarios passed, 0 failed, 0 skipped
41 steps passed, 0 failed, 0 skipped, 0 undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants