예제 #1
0
파일: tests.py 프로젝트: blundeln/wikidbase
 def testLogin(self):
   # Create admin user.
   from django.contrib.auth.create_superuser import createsuperuser
   createsuperuser('admin','*****@*****.**','admin')
   
   c = Client()
   #response = c.post('/accounts/login', {'username': '******', 'password': '******'})
   response = c.get('/accounts', {}, follow=True)
   d(response.status_code)
   d("content: " + response.content)
   self.assertTrue("you are not authorised" not in response.content)
예제 #2
0
파일: tests.py 프로젝트: blundeln/wikidbase
    def testLogin(self):
        # Create admin user.
        from django.contrib.auth.create_superuser import createsuperuser
        createsuperuser('admin', '*****@*****.**', 'admin')

        c = Client()
        #response = c.post('/accounts/login', {'username': '******', 'password': '******'})
        response = c.get('/accounts', {}, follow=True)
        d(response.status_code)
        d("content: " + response.content)
        self.assertTrue("you are not authorised" not in response.content)
예제 #3
0
파일: debug.py 프로젝트: blundeln/pylens
  def TESTS() :
    d("Testing")
    
    # Assert the ZeroDivisionError is thrown.
    with assert_raises(ZeroDivisionError) :
      x = 1 / 0

    # Assert that we expected the ZeroDivisionError to be thrown.
    with assert_raises(Exception) :
      with assert_raises(ZeroDivisionError) :
        x = 1 / 1
    
    # Confirm that the unexpected exception is let through.  My most beautiful test, ever!
    with assert_raises(IndexError) :
      with assert_raises(ZeroDivisionError) :
        x = []
        x[0] = 2
예제 #4
0
  def TESTS() :
    
    lens = List(AnyOf(nums, type=int), ",", type=list)
    d("GET")
    assert(lens.get("1,2,3") == [1,2,3])
    d("PUT")
    assert(lens.put([6,2,6,7,4,8]) == "6,2,6,7,4,8")

    # It was getting flattened due to And within And!
    test_description("Test a bug I found with nested lists.")
    INPUT = "1|2,3|4,5|6"
    lens = List(
             List(AnyOf(nums, type=int), "|", name="inner_list", type=list),
             ",", name="outer_list",
             type=list,
           )
    got = lens.get(INPUT)
    assert_equal(got, [[1,2],[3,4],[5,6]])
    got.insert(2, [6,7])
    assert_equal(lens.put(got), "1|2,3|4,6|7,5|6")
예제 #5
0
  def TESTS() :

    GlobalSettings.check_consumption = False
    
    lens = Word(alphanums, init_chars=alphas, type=str, max_count=5)
    d("GET")
    assert(lens.get("w23dffdf3") == "w23df")
    with assert_raises(LensException) :
      assert(lens.get("1w23dffdf3") == "w23df")

    d("PUT")
    assert(lens.put("R2D2") == "R2D2")
    
    with assert_raises(LensException) :
      lens.put("2234") == "R2D2"
    
    # XXX: Should fail if length checking working correctly.
    #with assert_raises(LensException) :
    #  lens.put("TooL0ng")
 
    
    d("Test with no type")
    lens = Word(alphanums, init_chars=alphas, max_count=5, default="a123d")
    assert(lens.get("w23dffdf3") == None)
    concrete_input_reader = ConcreteInputReader("ab12_3456")
    assert(lens.put(None, concrete_input_reader) == "ab12")
    assert(concrete_input_reader.get_remaining() == "_3456")
    assert(lens.put() == "a123d")
예제 #6
0
  def register_document_elements(self) :
    # Register roles
    for item_name in dir(self.translator_class) :
      # Normal roles
      if item_name.startswith("role_") :
        role_name = item_name.replace("role_", "")
        roles.register_canonical_role(role_name, generic_inline_role)
        d("Registered (normal) role %s" % role_name)
      # Raw roles.
      elif item_name.startswith("raw_role_") :
        role_name = item_name.replace("raw_role_", "")
        roles.register_canonical_role(role_name, generic_raw_role)
        d("Registered raw role %s" % role_name)

    # Register directives, first from this module, the from an extension module, so can overload.
    items = globals()
    if self.extension_module :
      items.update(self.extension_module.__dict__)
    for item_name, item in items.iteritems() :
      if inspect.isclass(item) and issubclass(item, WriterDirective) and item != WriterDirective:
        d("Registering directive %s" % item_name)
        directives.register_directive(item.__name__, item)
예제 #7
0
def run(command) :
  d(command)
  return os.system(command)
예제 #8
0
def generate_pages_from_example_code(python_file) :
  d(python_file)
  
  content = open(python_file).read()
 
  matches = []

  multiline_comment_matches = []
  for match in re.finditer("^\s\s\"\"\"(.+?)\"\"\".*?\n", content, re.DOTALL + re.MULTILINE) :
    if match:
      multiline_comment_matches.append(match)
  
  hash_comment_matches = []
  for match in re.finditer("^\s\s#(.*?)\n", content, re.DOTALL + re.MULTILINE) :
    if match:
      hash_comment_matches.append(match)

  
  test_function_matches = []
  for match in re.finditer("def\s+(.+?)_test.+?\n", content, re.DOTALL) :
    if match:
      test_function_matches.append(match)

  all_matches = []
  all_matches.extend(multiline_comment_matches)
  all_matches.extend(hash_comment_matches)
  all_matches.extend(test_function_matches)

  # Sort matches by their source positions.
  all_matches = sorted(all_matches, key=lambda x: x.start())
  
  output_blocks = []
  prev_match = None
  for match in all_matches:
    if prev_match :
      code_block = content[prev_match.end(0):match.start(0)].strip()

      if code_block :
        # Convert our assertions to showing expected outputs.
        def f(match) :
          args = match.group(1)
          if ",  " in args :
            # Since ',' may appear inside two args, we use double space to
            # indicate docs should be transformed in this way.
            return args.replace(",  ", " ---> ")
          else :
            return match.group(0)
        
        if "assert_equal" in code_block : 
          code_block = re.sub("assert_equal\((.+?)\)\s*$", f, code_block, flags=re.MULTILINE)
          # TODO: Need to handle multilines. 
          #code_block = re.sub("assert_equal\((.+?)\)\s*\n", f, code_block, flags=re.DOTALL)
          
        code_block = "\n\n::\n\n  %s\n\n" % code_block
        output_blocks.append([prev_match.end(0), code_block])
    prev_match = match


  match = None
  for match in all_matches:
    text = match.group(1)
    if match in test_function_matches:
      text = "\n\n" + " ".join([s.capitalize() for s in text.split("_")]) + "\n" + "-"*80 + "\n\n"
    elif match in multiline_comment_matches:
      text = text.replace("\n  ","\n")+"\n\n"
    elif match in hash_comment_matches:
      text = text[1:]+"\n"
    output_blocks.append((match.start(0), text))

  output_blocks = sorted(output_blocks, key=lambda x: x[0])

  output = ""
  for x in output_blocks :
    output += x[1]


  return output
예제 #9
0
파일: debug.py 프로젝트: blundeln/pylens
def test_description(msg) :
  """A debug message that will stand out."""
  msg = "========= " + msg + " ========="
  return d(msg)