Esempio n. 1
0
  def _CheckFileDifference(self, scenario_name):
    file_internal = test_util.TestResourceFilename(
        os.path.join('diff_codebases', 'codebase_internal', scenario_name))
    file_public = test_util.TestResourceFilename(
        os.path.join('diff_codebases', 'codebase_public', scenario_name))

    file_diff_obj = base.AreFilesDifferent(
        file_internal, file_public,
        relative_filename=scenario_name, record_full_diffs=True)
    print 'file_diff_obj for scenario %s: %s' % (scenario_name, file_diff_obj)

    expected_diff = open(test_util.TestResourceFilename(
        os.path.join('diff_codebases', scenario_name + '_diff'))).read()

    self.assertEquals(expected_diff.strip(), file_diff_obj.reason.strip())
Esempio n. 2
0
 def testIntermediateTask(self):
   basetest.CaptureTestStdout()
   t = self._ui.BeginIntermediateTask('foo', 'Fooing')
   with t:
     self._ui.Info('Bar')
   basetest.DiffTestStdout(
       test_util.TestResourceFilename('moe_ui/intermediate.txt'))
Esempio n. 3
0
 def testImmediateTask(self):
   basetest.CaptureTestStdout()
   t = self._ui.BeginImmediateTask('foo', 'Fooing')
   with t:
     pass
   basetest.DiffTestStdout(
       test_util.TestResourceFilename('moe_ui/immediate.txt'))
Esempio n. 4
0
  def testCodebaseDifference(self):
    codebase_internal = test_util.TestResourceFilename(
        os.path.join('diff_codebases', 'codebase_internal/'))
    codebase_public = test_util.TestResourceFilename(
        os.path.join('diff_codebases', 'codebase_public/'))

    codebase_diff_obj = base.AreCodebasesDifferent(
        codebase_utils.Codebase(codebase_internal),
        codebase_utils.Codebase(codebase_public),
        record_full_diffs=True)
    print 'codebase_diff_obj:', codebase_diff_obj

    expected_diff = open(test_util.TestResourceFilename(
        os.path.join('diff_codebases', 'codebase_diff'))).read()

    self.assertEquals(expected_diff.strip(), str(codebase_diff_obj).strip())
Esempio n. 5
0
 def testNestedTasks(self):
   basetest.CaptureTestStdout()
   t = self._ui.BeginIntermediateTask('foo', 'Fooing')
   with t:
     self._ui.Info('Bar')
     t2 = self._ui.BeginImmediateTask('baz', 'Bazing')
     with t2:
       pass
   basetest.DiffTestStdout(
       test_util.TestResourceFilename('moe_ui/nested.txt'))
Esempio n. 6
0
    def testCheckConfig(self):
        test_util.MockOutDatabase()
        test_util.MockOutMakeRepositoryConfig()
        FLAGS.project_config_file = test_util.TestResourceFilename(
            # We use the same project config as push_codebase_smoke_test
            os.path.join('push_codebase_smoke_test', 'project_config.txt'))

        check_config_cmd = simple_commands.CheckConfigCmd(
            'check_config', FLAGS)
        check_config_cmd.Run([])
Esempio n. 7
0
 def setUp(self):
     FLAGS.Reset()
     moe_app.InitForTest()
     self.stubs = stubout.StubOutForTesting()
     self.stubs.Set(db_client, '_Get', None)
     self.stubs.Set(db_client, '_Post', None)
     self.config_file_path = test_util.TestResourceFilename(
         'db_client/project_config.txt')
     self.name = 'foo'
     db_client.ServerBackedMoeDbClient = MockDbClient
     db_client.GetStoredProject = self._GetStoredProject
     test_util.MockOutMakeRepositoryConfig()
Esempio n. 8
0
    def RunScenario(self, config_file_name, codebase_expectation):
        # Mock out
        test_util.MockOutDatabase()
        test_util.MockOutMakeRepositoryConfig()

        FLAGS.project_config_file = test_util.TestResourceFilename(
            # We use the same project config as push_codebase_smoke_test
            os.path.join('push_codebase_smoke_test', config_file_name))

        CREATE.Run([])
        self.assertEqual([codebase_expectation], test_util.CREATED_CODEBASES)
        test_util.CREATED_CODEBASES = []
Esempio n. 9
0
    def RunScenario(self, config_file_name, codebase_expectations,
                    editor_expectations):
        # Mock out
        test_util.MockOutDatabase()
        test_util.MockOutMakeRepositoryConfig()

        FLAGS.project_config_file = test_util.TestResourceFilename(
            os.path.join('push_codebase_smoke_test', config_file_name))

        test_util.MockOutPusher(self, codebase_expectations,
                                editor_expectations)

        push_codebase.main([])
Esempio n. 10
0
    def testSimple(self):
        FLAGS.internal_revision = '1001'
        test_util.MockOutDatabase()
        test_util.MockOutMakeRepositoryConfig()

        FLAGS.project_config_file = test_util.TestResourceFilename(
            os.path.join('init_codebases', 'project_config.txt'))

        test_util.MockOutPusher(self, ('test_internal', '1001'),
                                ('test_public', 'head'))

        init_codebases.raw_input = lambda s: 'y'
        init_codebases.getpass.getpass = lambda s: 'fake_password'
        init_codebases.main([])
Esempio n. 11
0
    def testSpecifyAnEquivalence(self):
        test_util.MockOutDatabase()
        test_util.MockOutMakeRepositoryConfig(
            repository_configs={
                'test_internal': (None,
                                  test_util.StaticCodebaseCreator(
                                      {'1001': 'simple_python'})),
                'test_public': (
                    None,
                    test_util.StaticCodebaseCreator({'1': 'simple_python'}))
            })

        FLAGS.internal_revision = '1001'
        FLAGS.public_revision = '1'
        FLAGS.project_config_file = test_util.TestResourceFilename(
            os.path.join('init_codebases', 'project_config.txt'))
        init_codebases.main([])
Esempio n. 12
0
def setUp():
  global SCENARIOS_DIR
  SCENARIOS_DIR = test_util.TestResourceFilename('git_scenarios/')
  global UNRUN_SCENARIOS
  UNRUN_SCENARIOS = set(os.listdir(SCENARIOS_DIR))
Esempio n. 13
0
def setUp():
  global SCENARIOS_DIR
  SCENARIOS_DIR = test_util.TestResourceFilename('merge_codebases_scenarios/')
  global UNRUN_SCENARIOS
  UNRUN_SCENARIOS = set(os.listdir(SCENARIOS_DIR))
  moe_app.InitForTest()
Esempio n. 14
0
import os
import sys

import gflags as flags
from google.apputils import basetest

from moe import base
from moe import codebase_utils
from moe import moe_app
from moe.scrubber import scrubber
import test_util

FLAGS = flags.FLAGS

SCENARIOS_DIR = test_util.TestResourceFilename('regtest_scenarios/')
UNRUN_SCENARIOS = None


def setUp():
  # pylint: disable-msg=W0603
  global UNRUN_SCENARIOS
  UNRUN_SCENARIOS = set(os.listdir(SCENARIOS_DIR))
  moe_app.InitForTest()


def tearDown():
  # TODO(dbentley): I can't call assert in global tear down.
  if UNRUN_SCENARIOS:
    print 'UNRUN_SCENARIOS:', repr(UNRUN_SCENARIOS)
    sys.exit(1)
Esempio n. 15
0
    def testNonExistentButCreate(self):
        self.AllowPost()

        FLAGS.project_config_file = test_util.TestResourceFilename(
            'db_client/bar_project_config.txt')
        self.assertSucceeds(create_project=True)
Esempio n. 16
0
from google.apputils import file_util
import gflags as flags
from google.apputils import basetest

from moe import config_utils
from moe.scrubber import base
from moe.scrubber import comment_scrubber
from moe.scrubber import scrubber as scrubber_module
from moe.scrubber import sensitive_string_scrubber
import test_util
from moe.scrubber import usernames
from moe.scrubber import whitelist

FLAGS = flags.FLAGS

TEST_DATA_DIR = test_util.TestResourceFilename('comment_scrubber_test/')


class FakeContext(object):
    def __init__(self):
        self.errors = []

    def AddError(self, error):
        self.errors.append(error)


def TestCommentExtractor(test_case, extractor, source_file, expected_file):
    comments = extractor.ExtractComments(
        test_util.FakeFile(filename=source_file))
    expected_text = file_util.Read(expected_file)
    expected_json = simplejson.loads(expected_text)