Решение на Регулярни изрази от Ралица Великова

Обратно към всички решения

Към профила на Ралица Великова

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 39 неуспешни тест(а)

Код

class PrivacyFilter:
def __init__(self, text, preserve_phone_country_code = False, preserve_email_hostname = False, partially_preserve_email_username = False):
self._text = text
self.preserve_phone_country_code = preserve_phone_country_code
self.preserve_email_hostname = preserve_email_hostname
self.parially_preserve_email_username = parially_preserve_email_username
def filtered(text):
pass
class Validations:
def __init__(self, value):
self.value = value
def is_email(value):
pattern = r'^\w[\w\+_.-]{,200}@(\w.[\w-]{,61}[\w].[a-zA-Z]{2,3}?.[a-zA-Z]{2})*(\w.(\w-){,61}[\w])$'
return bool(re.search(pattern, value))
def is_hostname(value):
pattern = r'^(\w.[\w-]{,61}[\w].[a-zA-Z]{2,3}?.[a-zA-Z]{2})*(\w.(\w-){,61}[\w])$'
return bool(re.search(pattern, value))
def is_phone(value):
pattern = r'^(0|\b00|\+[1-9][0-9]{, 2})([ ()\-]{0,2}[0-9]){6,11}$'
return bool(re.search(pattern, value))
def is_ip_adress(value):
pattern = r'^[1-9][0-9]{, 2}.[1-9][0-9]{, 2}.[1-9][0-9]{, 2}.[1-9][0-9]{, 2}$'
return bool(re.search(pattern, value))
def is_number(value):
pattern = r'^?-(0|[1-9][0-9]*?.[0-9]*)$'
return bool(re.search(pattern, value))
def is_integer(value):
pattern = r'^?-(0|[1-9][0-9]*$'
return bool(re.search(pattern, value))
def is_date(value):
pattern = r'^[0-9][0-9][0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$'
return bool(re.search(pattern, value))
def is_time(value):
pattern = r'^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$'
return bool(re.search(pattern, value))
def is_datetime(value):
pattern = r'([0-9][0-9][0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1]))[T ](([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]))^$'
return bool(re.search(pattern, value))

Лог от изпълнението

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
======================================================================
ERROR: test_allows_email_hostname_to_be_preserved (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 54, in test_allows_email_hostname_to_be_preserved
    self.assertEqual('[FILTERED]@example.com', self.filter_email_usernames('someone@example.com'))
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 9, in filter_email_usernames
    filter = solution.PrivacyFilter(text)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_allows_email_usernames_to_be_partially_preserved (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 58, in test_allows_email_usernames_to_be_partially_preserved
    self.assertEqual('som[FILTERED]@example.com', self.partially_filter_email_usernames('someone@example.com'))
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 14, in partially_filter_email_usernames
    filter = solution.PrivacyFilter(text)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_does_not_brake_with_unicode (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 64, in test_does_not_brake_with_unicode
    self.assertEqual('За връзка: [FILTERED]@example.com', self.partially_filter_email_usernames('За връзка: me@example.com'))
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 14, in partially_filter_email_usernames
    filter = solution.PrivacyFilter(text)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_does_not_filter_invalid_emails (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 48, in test_does_not_filter_invalid_emails
    self.assertEqual(text, solution.PrivacyFilter(text).filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_does_not_filter_invalid_phone_numbers (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 86, in test_does_not_filter_invalid_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_filters_more_complex_phone_numbers (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 76, in test_filters_more_complex_phone_numbers
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_filters_whole_email_usernames_if_too_short (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 61, in test_filters_whole_email_usernames_if_too_short
    self.assertEqual('[FILTERED]@example.com', self.partially_filter_email_usernames('me@example.com'))
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 14, in partially_filter_email_usernames
    filter = solution.PrivacyFilter(text)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_obfuscates_more_complicated_emails (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 37, in test_obfuscates_more_complicated_emails
    self.assertEqual(filtered, solution.PrivacyFilter(text).filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_obfuscates_simple_emails (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 24, in test_obfuscates_simple_emails
    self.assertEqual('Contact: [EMAIL]', solution.PrivacyFilter('Contact: someone@example.com').filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_preserves_whitespace_around_phones (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 89, in test_preserves_whitespace_around_phones
    self.assertEqual(' [PHONE] or...', solution.PrivacyFilter(' +359881212-12-1 2 or...').filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_separates_preserved_country_code_from_filtered_phone_with_a_space (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 98, in test_separates_preserved_country_code_from_filtered_phone_with_a_space
    filter = solution.PrivacyFilter(text)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_works_with_blank_or_whitespace_strings_and_preserves_whitespace (test.PrivacyFilterTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 19, in test_works_with_blank_or_whitespace_strings_and_preserves_whitespace
    self.assertEqual('', solution.PrivacyFilter('').filtered())
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 6, in __init__
    self.parially_preserve_email_username = parially_preserve_email_username
NameError: global name 'parially_preserve_email_username' is not defined

======================================================================
ERROR: test_allows_huge_years_in_date_validation (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 246, in test_allows_huge_years_in_date_validation
    self.assertTrue(solution.Validations.is_date('9999-01-01'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 33, in is_date
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_allows_validation_for_emails (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 105, in test_allows_validation_for_emails
    self.assertTrue(solution.Validations.is_email('foo@bar.com'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 15, in is_email
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_allows_zero_years_in_date_validation (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 243, in test_allows_zero_years_in_date_validation
    self.assertTrue(solution.Validations.is_date('0000-01-01'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 33, in is_date
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_can_validate_more_complex_emails (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 124, in test_can_validate_more_complex_emails
    self.assertIs(solution.Validations.is_email(email), valid)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 15, in is_email
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_can_validate_more_complex_phone_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 160, in test_can_validate_more_complex_phone_numbers
    self.assertIs(solution.Validations.is_phone(phone), valid)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 21, in is_phone
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_does_not_allow_invalid_hours_minutes_or_seconds (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 270, in test_does_not_allow_invalid_hours_minutes_or_seconds
    self.assertFalse(solution.Validations.is_time('24:00:00'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 36, in is_time
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_does_not_allow_invalid_months_or_days_in_dates (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 254, in test_does_not_allow_invalid_months_or_days_in_dates
    self.assertFalse(solution.Validations.is_date('2012-13-01'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 33, in is_date
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_does_not_allow_zero_months_or_days_in_dates (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 249, in test_does_not_allow_zero_months_or_days_in_dates
    self.assertFalse(solution.Validations.is_date('1000-00-01'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 33, in is_date
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_does_not_break_on_emails_in_multiline_strings (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 127, in test_does_not_break_on_emails_in_multiline_strings
    self.assertFalse(solution.Validations.is_email("foo@bar.com\nwat?"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 15, in is_email
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_does_not_break_on_phones_in_multiline_strings (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 163, in test_does_not_break_on_phones_in_multiline_strings
    self.assertFalse(solution.Validations.is_phone("0885123123\nwat?"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 21, in is_phone
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_handles_multiline_strings_in_IP_validation_properly (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 189, in test_handles_multiline_strings_in_IP_validation_properly
    self.assertFalse(solution.Validations.is_ip_address("8.8.8.8\n"))
AttributeError: type object 'Validations' has no attribute 'is_ip_address'

======================================================================
ERROR: test_handles_multiline_strings_in_hostname_validation_properly (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 179, in test_handles_multiline_strings_in_hostname_validation_properly
    self.assertFalse(solution.Validations.is_hostname("foo.com\n"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 18, in is_hostname
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_handles_multiline_strings_in_integer_validation_properly (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 233, in test_handles_multiline_strings_in_integer_validation_properly
    self.assertFalse(solution.Validations.is_number("42\n24"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 27, in is_number
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_handles_multiline_strings_in_numbers_validation_properly (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 215, in test_handles_multiline_strings_in_numbers_validation_properly
    self.assertFalse(solution.Validations.is_number("42\n24"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 27, in is_number
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_handles_newlines_in_date_validation (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 259, in test_handles_newlines_in_date_validation
    self.assertFalse(solution.Validations.is_date("2012-11-19\n"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 33, in is_date
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_handles_newlines_in_time_and_datetime_validation (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 288, in test_handles_newlines_in_time_and_datetime_validation
    self.assertFalse(solution.Validations.is_time("12:01:01\n"))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 36, in is_time
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_returns_boolean_True_or_False (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 109, in test_returns_boolean_True_or_False
    self.assertIs(solution.Validations.is_email('foo@bar.com'), True)
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 15, in is_email
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_IP_addresses (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 183, in test_validates_IP_addresses
    self.assertTrue(solution.Validations.is_ip_address('1.2.3.4'))
AttributeError: type object 'Validations' has no attribute 'is_ip_address'

======================================================================
ERROR: test_validates_dates (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 237, in test_validates_dates
    self.assertTrue(solution.Validations.is_date('2012-11-19'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 33, in is_date
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_datetime_values (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 277, in test_validates_datetime_values
    self.assertTrue(solution.Validations.is_datetime('2012-11-19 19:00:00'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 39, in is_datetime
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_hostnames (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 166, in test_validates_hostnames
    self.assertTrue(solution.Validations.is_hostname('domain.tld'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 18, in is_hostname
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_integers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 219, in test_validates_integers
    self.assertTrue(solution.Validations.is_integer('42'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 30, in is_integer
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_more_complex_integers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 223, in test_validates_more_complex_integers
    self.assertFalse(solution.Validations.is_integer(' 42 '))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 30, in is_integer
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_more_complex_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 200, in test_validates_more_complex_numbers
    self.assertFalse(solution.Validations.is_number(' 42 '))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 27, in is_number
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 194, in test_validates_numbers
    self.assertTrue(solution.Validations.is_number('42'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 27, in is_number
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_phone_numbers (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 130, in test_validates_phone_numbers
    self.assertTrue(solution.Validations.is_phone('+35929555111'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 21, in is_phone
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

======================================================================
ERROR: test_validates_times (test.ValidationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140513-11348-h8vd2o/test.py", line 263, in test_validates_times
    self.assertTrue(solution.Validations.is_time('12:00:00'))
  File "/tmp/d20140513-11348-h8vd2o/solution.py", line 36, in is_time
    return bool(re.search(pattern, value))
NameError: global name 're' is not defined

----------------------------------------------------------------------
Ran 39 tests in 0.039s

FAILED (errors=39)

История (1 версия и 0 коментара)

Ралица обнови решението на 23.04.2014 16:51 (преди над 10 години)

+class PrivacyFilter:
+ def __init__(self, text, preserve_phone_country_code = False, preserve_email_hostname = False, partially_preserve_email_username = False):
+ self._text = text
+ self.preserve_phone_country_code = preserve_phone_country_code
+ self.preserve_email_hostname = preserve_email_hostname
+ self.parially_preserve_email_username = parially_preserve_email_username
+ def filtered(text):
+ pass
+
+class Validations:
+ def __init__(self, value):
+ self.value = value
+ def is_email(value):
+ pattern = r'^\w[\w\+_.-]{,200}@(\w.[\w-]{,61}[\w].[a-zA-Z]{2,3}?.[a-zA-Z]{2})*(\w.(\w-){,61}[\w])$'
+ return bool(re.search(pattern, value))
+ def is_hostname(value):
+ pattern = r'^(\w.[\w-]{,61}[\w].[a-zA-Z]{2,3}?.[a-zA-Z]{2})*(\w.(\w-){,61}[\w])$'
+ return bool(re.search(pattern, value))
+ def is_phone(value):
+ pattern = r'^(0|\b00|\+[1-9][0-9]{, 2})([ ()\-]{0,2}[0-9]){6,11}$'
+ return bool(re.search(pattern, value))
+ def is_ip_adress(value):
+ pattern = r'^[1-9][0-9]{, 2}.[1-9][0-9]{, 2}.[1-9][0-9]{, 2}.[1-9][0-9]{, 2}$'
+ return bool(re.search(pattern, value))
+ def is_number(value):
+ pattern = r'^?-(0|[1-9][0-9]*?.[0-9]*)$'
+ return bool(re.search(pattern, value))
+ def is_integer(value):
+ pattern = r'^?-(0|[1-9][0-9]*$'
+ return bool(re.search(pattern, value))
+ def is_date(value):
+ pattern = r'^[0-9][0-9][0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$'
+ return bool(re.search(pattern, value))
+ def is_time(value):
+ pattern = r'^([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$'
+ return bool(re.search(pattern, value))
+ def is_datetime(value):
+ pattern = r'([0-9][0-9][0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1]))[T ](([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]))^$'
+ return bool(re.search(pattern, value))