<s> from __future__ import unicode_literals <EOL> import logging <EOL> import os <EOL> import time <EOL> import shutil <EOL> import unittest <EOL> from django . test import TestCase , TransactionTestCase <EOL> from django . conf import settings <EOL> from django . db import transaction <EOL> from py4j . java_gateway import JavaGateway <EOL> from docutil . commands_util import get_encoding <EOL> from docutil . test_util import clean_test_dir <EOL> from codebase . models import CodeBase , CodeElementKind , CodeElement , MethodElement , CodeSnippet <EOL> from codebase . actions import start_eclipse , stop_eclipse , check_eclipse , create_code_db , create_code_local , list_code_db , list_code_local , link_eclipse , get_codebase_path , create_code_element_kinds , parse_code , clear_code_elements , get_project_code_words , diff_codebases , parse_snippets <EOL> from project . models import Project <EOL> from project . actions import create_project_local , create_project_db , create_release_db <EOL> from docutil . cache_util import clear_cache <EOL> class EclipseTest ( TestCase ) : <EOL> @ unittest . skip ( '<STR_LIT>' ) <EOL> def testEclipse ( self ) : <EOL> start_eclipse ( ) <EOL> self . assertTrue ( check_eclipse ( ) ) <EOL> stop_eclipse ( ) <EOL> class CodeSetup ( TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> start_eclipse ( ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> stop_eclipse ( ) <EOL> def setUp ( self ) : <EOL> logging . basicConfig ( level = logging . WARNING ) <EOL> settings . PROJECT_FS_ROOT = settings . PROJECT_FS_ROOT_TEST <EOL> create_project_local ( '<STR_LIT>' ) <EOL> create_project_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_release_db ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> create_release_db ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> Project . objects . all ( ) . delete ( ) <EOL> CodeElementKind . objects . all ( ) . delete ( ) <EOL> clean_test_dir ( ) <EOL> def testCreateCodeDB ( self ) : <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , CodeBase . objects . all ( ) . count ( ) ) <EOL> def testCreateCodeLocal ( self ) : <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> path = get_codebase_path ( '<STR_LIT>' , root = True ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( os . listdir ( path ) ) ) <EOL> def testListCodeLocal ( self ) : <EOL> self . assertEqual ( <NUM_LIT:0> , len ( list_code_local ( '<STR_LIT>' ) ) ) <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( list_code_local ( '<STR_LIT>' ) ) ) <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( list_code_local ( '<STR_LIT>' ) ) ) <EOL> def testListCodeDB ( self ) : <EOL> self . assertEqual ( <NUM_LIT:0> , len ( list_code_db ( '<STR_LIT>' ) ) ) <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( list_code_db ( '<STR_LIT>' ) ) ) <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( list_code_db ( '<STR_LIT>' ) ) ) <EOL> def testCreateCodeElementKinds ( self ) : <EOL> create_code_element_kinds ( ) <EOL> kind_count = CodeElementKind . objects . all ( ) . count ( ) <EOL> self . assertEqual ( <NUM_LIT:30> , kind_count ) <EOL> def testLinkEclipseProject ( self ) : <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> to_path = get_codebase_path ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> to_path = os . path . join ( to_path , '<STR_LIT:src>' ) <EOL> os . rmdir ( to_path ) <EOL> from_path = os . path . join ( settings . TESTDATA , '<STR_LIT>' , '<STR_LIT:src>' ) <EOL> shutil . copytree ( from_path , to_path ) <EOL> link_eclipse ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> gateway = JavaGateway ( ) <EOL> workspace = gateway . jvm . org . eclipse . core . resources . ResourcesPlugin . getWorkspace ( ) <EOL> root = workspace . getRoot ( ) <EOL> pm = gateway . jvm . org . eclipse . core . runtime . NullProgressMonitor ( ) <EOL> project1 = root . getProject ( '<STR_LIT>' ) <EOL> self . assertIsNotNone ( project1 ) <EOL> project1 . delete ( True , True , pm ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> gateway . close ( ) <EOL> class CodeParserTest ( TransactionTestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> settings . PROJECT_FS_ROOT = settings . PROJECT_FS_ROOT_TEST <EOL> start_eclipse ( ) <EOL> create_project_local ( '<STR_LIT>' ) <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> to_path = get_codebase_path ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> to_path = os . path . join ( to_path , '<STR_LIT:src>' ) <EOL> os . rmdir ( to_path ) <EOL> from_path = os . path . join ( settings . TESTDATA , '<STR_LIT>' , '<STR_LIT:src>' ) <EOL> shutil . copytree ( from_path , to_path ) <EOL> link_eclipse ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_code_local ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> to_path = get_codebase_path ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> to_path = os . path . join ( to_path , '<STR_LIT:src>' ) <EOL> os . rmdir ( to_path ) <EOL> from_path = os . path . join ( settings . TESTDATA , '<STR_LIT>' , '<STR_LIT:src>' ) <EOL> shutil . copytree ( from_path , to_path ) <EOL> link_eclipse ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> gateway = JavaGateway ( ) <EOL> workspace = gateway . jvm . org . eclipse . core . resources . ResourcesPlugin . getWorkspace ( ) <EOL> root = workspace . getRoot ( ) <EOL> pm = gateway . jvm . org . eclipse . core . runtime . NullProgressMonitor ( ) <EOL> project1 = root . getProject ( '<STR_LIT>' ) <EOL> project1 . delete ( True , True , pm ) <EOL> project1 = root . getProject ( '<STR_LIT>' ) <EOL> project1 . delete ( True , True , pm ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> gateway . close ( ) <EOL> stop_eclipse ( ) <EOL> clean_test_dir ( ) <EOL> @ transaction . commit_on_success <EOL> def setUp ( self ) : <EOL> clear_cache ( ) <EOL> logging . basicConfig ( level = logging . WARNING ) <EOL> create_code_element_kinds ( ) <EOL> self . project = create_project_db ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> create_release_db ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> create_release_db ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ transaction . commit_on_success <EOL> def tearDown ( self ) : <EOL> Project . objects . all ( ) . delete ( ) <EOL> CodeElementKind . objects . all ( ) . delete ( ) <EOL> clear_cache ( ) <EOL> @ transaction . autocommit <EOL> def testCodeWords ( self ) : <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> parse_code ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> code_words = get_project_code_words ( Project . objects . get ( dir_name = '<STR_LIT>' ) ) <EOL> self . assertTrue ( '<STR_LIT>' in code_words ) <EOL> self . assertTrue ( '<STR_LIT>' in code_words ) <EOL> self . assertTrue ( '<STR_LIT>' not in code_words ) <EOL> self . assertEqual ( <NUM_LIT:12> , len ( code_words ) ) <EOL> @ transaction . autocommit <EOL> def testJavaDiff ( self ) : <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> parse_code ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> parse_code ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cdiff = diff_codebases ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:4> , cdiff . packages_size_from ) <EOL> self . assertEqual ( <NUM_LIT:5> , cdiff . packages_size_to ) <EOL> self . assertEqual ( <NUM_LIT:1> , cdiff . added_packages . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , cdiff . removed_packages . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:20> , cdiff . types_size_from ) <EOL> self . assertEqual ( <NUM_LIT> , cdiff . types_size_to ) <EOL> self . assertEqual ( <NUM_LIT:1> , cdiff . added_types . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , cdiff . removed_types . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT> , cdiff . methods_size_from ) <EOL> self . assertEqual ( <NUM_LIT> , cdiff . methods_size_to ) <EOL> self . assertEqual ( <NUM_LIT:1> , cdiff . added_methods . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , cdiff . removed_methods . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , cdiff . fields_size_from ) <EOL> self . assertEqual ( <NUM_LIT:4> , cdiff . fields_size_to ) <EOL> self . assertEqual ( <NUM_LIT:0> , cdiff . added_fields . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , cdiff . removed_fields . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:6> , cdiff . ann_fields_size_from ) <EOL> self . assertEqual ( <NUM_LIT:5> , cdiff . ann_fields_size_to ) <EOL> self . assertEqual ( <NUM_LIT:0> , cdiff . added_ann_fields . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , cdiff . removed_ann_fields . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:5> , cdiff . enum_values_size_from ) <EOL> self . assertEqual ( <NUM_LIT:7> , cdiff . enum_values_size_to ) <EOL> self . assertEqual ( <NUM_LIT:0> , cdiff . added_enum_values . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , cdiff . removed_enum_values . count ( ) ) <EOL> def load_snippets ( self ) : <EOL> from_path = os . path . join ( settings . TESTDATA , '<STR_LIT>' ) <EOL> snippets = [ ] <EOL> for i , path in enumerate ( sorted ( os . listdir ( from_path ) ) ) : <EOL> if path . endswith ( '<STR_LIT>' ) : <EOL> with open ( os . path . join ( from_path , path ) ) as f : <EOL> text = f . read ( ) <EOL> encoding = get_encoding ( text ) <EOL> content = unicode ( text , encoding ) <EOL> snippet = CodeSnippet ( <EOL> index = i , <EOL> project = self . project , <EOL> snippet_text = content , <EOL> language = '<STR_LIT>' , <EOL> source = '<STR_LIT:d>' , <EOL> ) <EOL> snippet . save ( ) <EOL> snippets . append ( snippet ) <EOL> return snippets <EOL> @ transaction . autocommit <EOL> def testJavaSnippetParser ( self ) : <EOL> snippets = self . load_snippets ( ) <EOL> parse_snippets ( '<STR_LIT>' , '<STR_LIT:d>' , '<STR_LIT>' ) <EOL> snippet = CodeSnippet . objects . get ( pk = snippets [ <NUM_LIT:0> ] . pk ) <EOL> contents = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> self . assertEqual ( len ( contents ) , <EOL> snippet . single_code_references . count ( ) ) <EOL> for content , ref in zip ( contents , snippet . single_code_references . order_by ( '<STR_LIT:index>' ) ) : <EOL> self . assertEqual ( content , ref . content ) <EOL> @ transaction . autocommit <EOL> def testJavaCodeParser ( self ) : <EOL> create_code_db ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> codebase = parse_code ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . simple_name ) <EOL> self . assertEqual ( '<STR_LIT:class>' , ce . kind . kind ) <EOL> ce2 = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertTrue ( ce2 . abstract ) <EOL> self . assertEqual ( <NUM_LIT:1> , ce . containees . count ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . simple_name ) <EOL> self . assertEqual ( '<STR_LIT:class>' , ce . kind . kind ) <EOL> self . assertEqual ( <NUM_LIT:1> , ce . containees . count ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> self . assertEqual ( <NUM_LIT:2> , <EOL> CodeElement . objects . filter ( simple_name = '<STR_LIT>' ) . count ( ) ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , ce . parents . count ( ) ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> fqns = [ parent . fqn for parent in ce . parents . all ( ) ] <EOL> self . assertTrue ( '<STR_LIT>' in fqns ) <EOL> self . assertTrue ( '<STR_LIT>' in fqns ) <EOL> self . assertTrue ( '<STR_LIT>' in fqns ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . simple_name ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containees . all ( ) [ <NUM_LIT:0> ] . simple_name ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> ce . containees . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> method = ce . methodelement <EOL> self . assertEqual ( <NUM_LIT:4> , method . parameters_length ) <EOL> self . assertTrue ( MethodElement . objects . filter ( simple_name = '<STR_LIT>' ) <EOL> . filter ( parameters_length = <NUM_LIT:4> ) . exists ( ) ) <EOL> self . assertEqual ( <NUM_LIT:4> , ce . parameters ( ) . count ( ) ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . parameters ( ) . all ( ) [ <NUM_LIT:3> ] . simple_name ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . parameters ( ) . all ( ) [ <NUM_LIT:2> ] . type_fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . parameters ( ) . all ( ) [ <NUM_LIT:3> ] . type_fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> ce . parameters ( ) . all ( ) [ <NUM_LIT:3> ] . kind . kind ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . methodelement . return_fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . methodelement . return_fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . simple_name ) <EOL> self . assertEqual ( '<STR_LIT:int>' , ce . fieldelement . type_simple_name ) <EOL> self . assertEqual ( '<STR_LIT:int>' , ce . fieldelement . type_fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . fieldelement . type_fqn ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containers . all ( ) [ <NUM_LIT:0> ] . fqn ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertTrue ( ce . kind . is_type ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> ce . containees . all ( ) [ <NUM_LIT:0> ] . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> ce . containees . all ( ) [ <NUM_LIT:0> ] . fieldelement . type_fqn ) <EOL> simple_names = [ v . simple_name for v in ce . containees . all ( ) ] <EOL> self . assertTrue ( '<STR_LIT>' in simple_names ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( simple_names ) ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertTrue ( ce . kind . is_type ) <EOL> simple_names = [ v . simple_name for v in ce . containees . all ( ) ] <EOL> self . assertTrue ( '<STR_LIT>' in simple_names ) <EOL> self . assertTrue ( '<STR_LIT>' not in simple_names ) <EOL> self . assertTrue ( '<STR_LIT>' in simple_names ) <EOL> self . assertTrue ( '<STR_LIT>' not in simple_names ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( simple_names ) ) <EOL> ce = CodeElement . objects . get ( fqn = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . kind . kind ) <EOL> self . assertEqual ( '<STR_LIT>' , ce . containees . all ( ) [ <NUM_LIT:0> ] . kind . kind ) <EOL> fooBar = ce . containees . filter ( simple_name = '<STR_LIT>' ) . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( '<STR_LIT>' , fooBar . fieldelement . type_fqn ) <EOL> self . assertEqual ( <NUM_LIT:6> , ce . containees . count ( ) ) <EOL> self . assertEqual ( <NUM_LIT> , codebase . code_elements . count ( ) ) <EOL> clear_code_elements ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT> , codebase . code_elements . count ( ) ) <EOL> clear_code_elements ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:0> , codebase . code_elements . count ( ) ) </s>
