Comments (7)
However, how do you represent a special marker that renders to an empty string?
With the appropriate character escape; '\xad' in this case.
from zope.testbrowser.
That does not seem to help. To be concise, I have a linked article named Yet another test article
. So in my browser.contents
is something like
<a href="http://localhost/portal/++co++3e6e4494-5e6b-11e4-9a68-b8e85636a62a"
title="go to page 'Yet another test article'">
Yet ano­ther test ar­tic­le
</a>
All of the following examples throw a LinkNotFoundError
(tried it with and without unicode strings):
browser.getLink(u'Yet another test article')
browser.getLink(u'Yet ano­ther test ar­tic­le')
browser.getLink(u'Yet ano\xadther test ar\xadtic\xadle')
from zope.testbrowser.
@florianpilz can you reduce your problem to a testcase? Because the following passes for me, when applied to master:
diff --git a/src/zope/testbrowser/tests/test_browser.py b/src/zope/testbrowser/tests/test_browser.py
index f9b8550..ec14cbb 100644
--- a/src/zope/testbrowser/tests/test_browser.py
+++ b/src/zope/testbrowser/tests/test_browser.py
@@ -489,6 +489,28 @@ def test_strip_linebreaks_from_textarea(self):
"""
+def test_soft_hyphens():
+ r"""
+
+ >>> app = TestApp()
+ >>> browser = Browser(wsgi_app=app)
+
+ >>> app.set_next_response(b'''\
+ ... <html><body>
+ ... <a href="foo">hy­phen­ation</a>
+ ... </body></html>
+ ... ''')
+ >>> browser.open('http://localhost/bar') # doctest: +ELLIPSIS
+ GET /bar HTTP/1.1
+ ...
+
+ >>> link = browser.getLink(u'hy\xadphen\xadation')
+ >>> link.url
+ 'http://localhost/foo'
+
+ """
+
+
def test_relative_link():
"""
RFC 1808 specifies how relative URLs should be resolved, let's see
from zope.testbrowser.
Okay, I can reproduce this in the 4.0 branch:
diff --git a/src/zope/testbrowser/tests/test_browser.py b/src/zope/testbrowser/tests/test_browser.py
index 915ce48..45f4fad 100644
--- a/src/zope/testbrowser/tests/test_browser.py
+++ b/src/zope/testbrowser/tests/test_browser.py
@@ -379,6 +379,25 @@ def test_strip_linebreaks_from_textarea(self):
"""
+def test_soft_hyphens():
+ r"""
+
+ >>> browser = Browser()
+ >>> browser.open('''\
+ ... <html><body>
+ ... <a href="foo">link</a>
+ ... </body></html>
+ ... ''', url='http://localhost/bar') # doctest: +ELLIPSIS
+ GET /bar HTTP/1.1
+ ...
+
+ >>> link = browser.getLink(u'hy\xadphen\xadation')
+ >>> link.url
+ 'http://localhost/foo'
+
+ """
+
+
def test_relative_link():
"""
RFC 1808 specifies how relative URLs should be resolved, let's see
Fails with LinkNotFoundError.
from zope.testbrowser.
Never mind, I messed up the test case. This passes on the 4.0
branch:
diff --git a/src/zope/testbrowser/tests/test_browser.py b/src/zope/testbrowser/tests/test_browser.py
index 915ce48..78a9161 100644
--- a/src/zope/testbrowser/tests/test_browser.py
+++ b/src/zope/testbrowser/tests/test_browser.py
@@ -379,6 +379,25 @@ def test_strip_linebreaks_from_textarea(self):
"""
+def test_soft_hyphens():
+ r"""
+
+ >>> browser = Browser()
+ >>> browser.open('''\
+ ... <html><body>
+ ... <a href="foo">hy­phen­ation</a>
+ ... </body></html>
+ ... ''', url='http://localhost/bar') # doctest: +ELLIPSIS
+ GET /bar HTTP/1.1
+ ...
+
+ >>> link = browser.getLink(u'hy\xadphen\xadation')
+ >>> link.url
+ 'http://localhost/foo'
+
+ """
+
+
def test_relative_link():
"""
RFC 1808 specifies how relative URLs should be resolved, let's see
from zope.testbrowser.
Hm, seems like you are right.
I found out that the UTF-8 representation of shy-Markers works, i.e. using '\xc2\xad'
or '\xad'.encode('utf-8')
. Therefore it seems to be an encoding issue somewhere else.
Maybe the mechanize Browser is the issue, I cannot tell for certain since you mock some parts out when testing zope.testbrowser
.
Anyway, the problem lies definitely in another package. Thanks for helping!
from zope.testbrowser.
Ok nailed it down: We are using Zope2 as the test app, which sets UTF-8 encoding in the header. Mechanize just looks into the header to determine the encoding. Thus it's not an error after all, just cumbersome.
But be aware that using browser.getLink(u'hy\xadphen\xadation')
only works in your test setup. Mechanize always uses an encoding, which defaults to latin1
. In your tests you obviously mocked that part, since you define the exact response given.
So using the Unicode-representation will not work using a real Mechanize Browser. Instead you have to use the representation of your encoding or encode the text string, e.g. browser.getLink(u'hy\xadphen\xadation'.encode('latin1'))
from zope.testbrowser.
Related Issues (20)
- displayValue setter silently ignores values which are not in displayOptions HOT 1
- Sphinx doctests are broken in Python 3 HOT 2
- Fix DeprecationWarnings
- Careless use of CSS selectors breaks with new BeautifulSoup HOT 1
- Tests are broken on master HOT 3
- Cookie tests fail in different locales
- ItemControl.click() lets you uncheck radio buttons
- getLink() used to see iframes, now it doesn't
- Value of unchecked checkboxes changed from False to [] in zope.testbrowser 5.0.0 HOT 2
- getControl('Label') cannot find hidden inputs any more
- .reload() fails if the previous request was a POST HOT 1
- .reload() does not follow redirects nor does it raise exceptions for bad HTTP statuses HOT 1
- getLink() used to consider the whole enclosed text content, now it only looks at the directly contained text
- Allow option to prevent auto redirection HOT 1
- Python 3.8 support HOT 2
- getLink now tests regexes using .match, not .search HOT 1
- getLink uses stale cached HTML after goBack
- Browser._preparedRequest is a bit overenthusiastic about setting Referer HOT 1
- Browser._findAllControls() has wrong behaviour with no-name inputs and checkboxes HOT 1
- Replace `.browser.SetattrErrorsMixin` with `__slots__`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zope.testbrowser.