<commit_before>from formalchemy.tests import *
from formalchemy.renderers import *
import datetime


__doc__ = r"""
Let's test the behavior of a Field element, returning a modified copy of itself
when we call some methods on it:

  >>> fs = FieldSet(User)
  >>> fs.password
  AttributeField(password)
  >>> fs.password.renderer
  <TextFieldRenderer for AttributeField(password)>

Two tests to show that with_renderer doesn't change the Field in place.

  >>> fs.password.with_renderer(PasswordFieldRenderer).renderer
  <PasswordFieldRenderer for AttributeField(password)>
  >>> fs.password.renderer
  <TextFieldRenderer for AttributeField(password)>
  
Now let's try to modify it. First, we call configure(), so that the fields of
the model are "copied" to the `render_fields` - the fields to actually be
rendered.

  >>> fs.configure()
  >>> fs.modify(fs.password.with_renderer(PasswordFieldRenderer))  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> fs.password.renderer
  <PasswordFieldRenderer for AttributeField(password)>

# Test append - tested in test_fieldset_api.py

# Test insert_after
Continuing with this `fs`:

  >>> fs.append(Field('passwd1'))  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> 

# Test insert_at_index
# Test caching system, including rebind
#   see http://groups.google.com/group/formalchemy/browse_thread/thread/958887f41ed4dd71<commit_msg>Test insert_at_index, insert_after<commit_after>from formalchemy.tests import *
from formalchemy.renderers import *
import datetime


__doc__ = r"""
Let's test the behavior of a Field element, returning a modified copy of itself
when we call some methods on it:

  >>> fs = FieldSet(User)
  >>> fs.password
  AttributeField(password)
  >>> fs.password.renderer
  <TextFieldRenderer for AttributeField(password)>

Two tests to show that with_renderer doesn't change the Field in place.

  >>> fs.password.with_renderer(PasswordFieldRenderer).renderer
  <PasswordFieldRenderer for AttributeField(password)>
  >>> fs.password.renderer
  <TextFieldRenderer for AttributeField(password)>
  
Now let's try to modify it. First, we call configure(), so that the fields of
the model are "copied" to the `render_fields` - the fields to actually be
rendered.

  >>> fs.configure()
  >>> fs.modify(fs.password.with_renderer(PasswordFieldRenderer))  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> fs.password.renderer
  <PasswordFieldRenderer for AttributeField(password)>

Continuing with this `fs`, testing `insert_after`:

  >>> fs.append(Field('passwd1'))  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> fs.insert_after('name', fs.passwd1)  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> fs._fields.keys()
  ['id', 'email', 'password', 'name', 'orders']
  >>> fs._render_fields.keys()
  ['email', 'password', 'name', 'passwd1', 'orders']

Kind of the same thing with insert_at_index:

  >>> fs.append(Field('passwd2'))  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> fs.insert_at_index(4, fs.passwd2)  #doctest: +ELLIPSIS
  <formalchemy.tests.FieldSet object ...>
  >>> fs._render_fields.keys()
  ['email', 'password', 'name', '<PASSWORD>', '<PASSWORD>', 'orders']

# Test caching system, including rebind
#   see http://groups.google.com/group/formalchemy/browse_thread/thread/958887f41ed4dd71
{'fraction_non_alphanumeric': 0.12684801892371378, 'fraction_numerical': 0.008574807806031934, 'mean_word_length': 4.955985915492958, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '652060', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1036, 'n_words': 281}