Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Split alt tests out, to be run manually
Browse files Browse the repository at this point in the history
  • Loading branch information
Will McCutchen committed Feb 22, 2013
1 parent 12d1d2b commit fc75b81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -60,6 +60,12 @@ Run the tests:

py.test

If you'd like to test some alternate Python implentations
([twitter-text-python][6] and [twitter-text-py][7]) of the same idea,
you'll have to run those tests a little more manually:

py.test tests/alt*

## See Also

Twitter's own docs about this inane misfeature:
Expand All @@ -71,3 +77,5 @@ https://dev.twitter.com/docs/tco-url-wrapper/how-twitter-wrap-urls
[3]: https://github.com/twitter/twitter-text-java
[4]: https://github.com/twitter/twitter-text-conformance
[5]: https://github.com/twitter/twitter-text-rb/blob/master/lib/regex.rb
[6]: https://github.com/BonsaiDen/twitter-text-python
[7]: https://github.com/dryan/twitter-text-py
18 changes: 18 additions & 0 deletions tests/alt_test_twitter_text_py.py
@@ -0,0 +1,18 @@
# Tests the twitter-text-py library for conformance
# https://github.com/dryan/twitter-text-py

import sys
from test_twitter_regex import pytest_generate_tests


try:
import twitter_text
except ImportError, e:
print >> sys.stderr, 'Unable to load alt implemenatation: %s' % e
print >> sys.stderr, 'Please run `git submodule update --init`'
sys.exit(1)


def test_twitter_text_py(description, text, expected):
results = twitter_text.extractor.Extractor(text).extract_urls()
assert expected == results
18 changes: 18 additions & 0 deletions tests/alt_test_twitter_text_python.py
@@ -0,0 +1,18 @@
# Test the twitter-text-python library for conformance
# https://github.com/BonsaiDen/twitter-text-python

import sys
from test_twitter_regex import pytest_generate_tests


try:
import ttp
except ImportError, e:
print >> sys.stderr, 'Unable to load alt implemenatation: %s' % e
print >> sys.stderr, 'Please run `git submodule update --init`'
sys.exit(1)


def test_twitter_text_py(description, text, expected):
result = ttp.Parser().parse(text)
assert expected == result.urls
22 changes: 6 additions & 16 deletions tests/test_url_extraction.py → tests/test_twitter_regex.py
Expand Up @@ -4,6 +4,7 @@
import yaml
import twitter_regex


url_test_path = 'tests/twitter-text-conformance/extract.yml'
try:
url_tests = yaml.load(open(url_test_path))['tests']['urls']
Expand All @@ -12,31 +13,20 @@
print >> sys.stderr, 'Please run `git submodule update --init`'
sys.exit(1)


# Add alt implementation paths to sys.path
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
alt_impl_root = os.path.join(root, 'alt_impls')
for alt_impl in os.listdir(alt_impl_root):
sys.path.insert(0, os.path.join(alt_impl_root, alt_impl))
try:
import twitter_text
import ttp
except ImportError, e:
print >> sys.stderr, 'Unable to load alt implemenatation: %s' % e
print >> sys.stderr, 'Please run `git submodule update --init`'
sys.exit(1)


def pytest_generate_tests(metafunc):
for spec in url_tests:
metafunc.addcall(spec)

def test_url_extraction(description, text, expected):

def test_twitter_regex(description, text, expected):
matches = re.findall(twitter_regex.REGEXEN['valid_url'], text)
results = [match[2] for match in matches if match]
assert expected == results

def test_twitter_text_py(description, text, expected):
results = twitter_text.extractor.Extractor(text).extract_urls()
assert expected == results

def test_twitter_text_python(description, text, expected):
result = ttp.Parser().parse(text)
assert expected == result.urls

0 comments on commit fc75b81

Please sign in to comment.