# Path: test/stub_config.py
# class StubConfig(object):
#     def __init__(self):
#         pass
# 
#     def development_dir(self):
#         return StubConfig.DEVELOPMENT_DIR
# 
#     def debug_dir(self):
#         return StubConfig.DEBUG_DIR
# 
#     def production_dir(self):
#         return StubConfig.PRODUCTION_DIR
# 
#     def compiled_js_ext(self):
#         return StubConfig.COMPILED_JS_EXT
# 
#     def test_file_pattern(self):
#         return StubConfig.TEST_FILE_PATTERN
# 
#     def library_root(self):
#         return StubConfig.LIBRARRY_ROOT
# 
#     def closurebuilder(self):
#         return StubConfig.CLOSUREBUILDER
# 
#     def depswriter(self):
#         return StubConfig.DEPSWRITER
# 
#     def compiler_root(self):
#         return StubConfig.COMPILER_ROOT
# 
#     def base_js(self):
#         return StubConfig.BASE_JS
# 
#     def multitestrunner_css(self):
#         return StubConfig.MULTI_TEST_RUNNER_CSS
# 
#     def js_dev_dir(self):
#         return StubConfig.JS_DEV_DIR
# 
#     def deps_js(self):
#         return StubConfig.DEPS_JS
# 
#     def testrunner(self):
#         return StubConfig.TESTRUNNER
# 
#     def compiler(self):
#         return StubConfig.COMPILER
# 
#     def compilation_level(self):
#         return StubConfig.COMPILATION_LEVEL
# 
#     def compiler_zip(self):
#         return StubConfig.COMPILER_LATEST_ZIP
# 
#     def library_repos(self):
#         return StubConfig.LIBRARY_GIT_REPOS
# 
#     def compiler_flagfile(self):
#         return StubConfig.COMPILER_FLAGFILE
# 
#     def compiler_flagfile_for_debug(self):
#         return StubConfig.COMPILER_FLAGFILE_FOR_DEBUG
# 
#     def linter_flagfile(self):
#         return StubConfig.LINTER_FLAGFILE
# 
# class StubConfigOnStubProject(object):
#     def __init__(self):
#         pass
# 
#     def development_dir(self):
#         return StubConfigOnStubProject.DEVELOPMENT_DIR
# 
#     def debug_dir(self):
#         return StubConfigOnStubProject.DEBUG_DIR
# 
#     def production_dir(self):
#         return StubConfigOnStubProject.PRODUCTION_DIR
# 
#     def compiled_js_ext(self):
#         return StubConfigOnStubProject.COMPILED_JS_EXT
# 
#     def test_file_pattern(self):
#         return StubConfigOnStubProject.TEST_FILE_PATTERN
# 
#     def library_root(self):
#         return StubConfigOnStubProject.LIBRARRY_ROOT
# 
#     def closurebuilder(self):
#         return StubConfigOnStubProject.CLOSUREBUILDER
# 
#     def depswriter(self):
#         return StubConfigOnStubProject.DEPSWRITER
# 
#     def compiler_root(self):
#         return StubConfigOnStubProject.COMPILER_ROOT
# 
#     def base_js(self):
#         return StubConfigOnStubProject.BASE_JS
# 
#     def multitestrunner_css(self):
#         return StubConfigOnStubProject.MULTI_TEST_RUNNER_CSS
# 
#     def js_dev_dir(self):
#         return StubConfigOnStubProject.JS_DEV_DIR
# 
#     def deps_js(self):
#         return StubConfigOnStubProject.DEPS_JS
# 
#     def testrunner(self):
#         return StubConfigOnStubProject.TESTRUNNER
# 
#     def compiler(self):
#         return StubConfigOnStubProject.COMPILER
# 
#     def compilation_level(self):
#         return StubConfigOnStubProject.COMPILATION_LEVEL
# 
#     def compiler_zip(self):
#         return StubConfigOnStubProject.COMPILER_LATEST_ZIP
# 
#     def library_repos(self):
#         return StubConfigOnStubProject.LIBRARY_GIT_REPOS
# 
#     def compiler_flagfile(self):
#         return StubConfigOnStubProject.COMPILER_FLAGFILE
# 
#     def compiler_flagfile_for_debug(self):
#         return StubConfigOnStubProject.COMPILER_FLAGFILE_FOR_DEBUG
# 
#     def linter_flagfile(self):
#         return StubConfigOnStubProject.LINTER_FLAGFILE
# 
# Path: test/stub_environment.py
# class StubEnvironment(object):
#     def __init__(self):
#         self.cwd = None
#         self.tree = None
#         self.argument = None


import unittest
import doctest
import os
import subprocess
import googkit.lib.strutil
import googkit.commands.build
from googkit.compat.unittest import mock
from test.stub_config import StubConfig, StubConfigOnStubProject
from test.stub_environment import StubEnvironment
        expected.compiler_arg('--flagfile', StubConfig.COMPILER_FLAGFILE)

        self.cmd.compiled_js_path = mock.MagicMock()
        self.cmd.compiled_js_path.side_effect = lambda _: 'dummy.JS'

        with mock.patch('os.path.exists', return_value=True):
            args = self.cmd.production_arguments('dummy.html', StubConfig.PROJECT_DIR)
        self.assertEqual(args, expected)


    def test_build_production(self):
        self.cmd.setup_files = mock.MagicMock()
        self.cmd.production_arguments = mock.MagicMock()
        self.cmd.production_arguments.return_value = ['ARG']

        MockPopen = mock.MagicMock()
        mock_popen = MockPopen.return_value
        # It simulates the command was succeeded
        mock_popen.returncode = 0

        with mock.patch('subprocess.Popen', new=MockPopen):
            self.cmd.build_production(StubConfig.PROJECT_DIR, False)

        self.cmd.setup_files.assert_called_once_with(StubConfig.PRODUCTION_DIR, False)
        MockPopen.assert_called_once_with(
            ['python', StubConfig.CLOSUREBUILDER, 'ARG'],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

    def test_build_debug(self):

# Path: test/stub_config.py
# class StubConfig(object):
#     def __init__(self):
#         pass
# 
#     def development_dir(self):
#         return StubConfig.DEVELOPMENT_DIR
# 
#     def debug_dir(self):
#         return StubConfig.DEBUG_DIR
# 
#     def production_dir(self):
#         return StubConfig.PRODUCTION_DIR
# 
#     def compiled_js_ext(self):
#         return StubConfig.COMPILED_JS_EXT
# 
#     def test_file_pattern(self):
#         return StubConfig.TEST_FILE_PATTERN
# 
#     def library_root(self):
#         return StubConfig.LIBRARRY_ROOT
# 
#     def closurebuilder(self):
#         return StubConfig.CLOSUREBUILDER
# 
#     def depswriter(self):
#         return StubConfig.DEPSWRITER
# 
#     def compiler_root(self):
#         return StubConfig.COMPILER_ROOT
# 
#     def base_js(self):
#         return StubConfig.BASE_JS
# 
#     def multitestrunner_css(self):
#         return StubConfig.MULTI_TEST_RUNNER_CSS
# 
#     def js_dev_dir(self):
#         return StubConfig.JS_DEV_DIR
# 
#     def deps_js(self):
#         return StubConfig.DEPS_JS
# 
#     def testrunner(self):
#         return StubConfig.TESTRUNNER
# 
#     def compiler(self):
#         return StubConfig.COMPILER
# 
#     def compilation_level(self):
#         return StubConfig.COMPILATION_LEVEL
# 
#     def compiler_zip(self):
#         return StubConfig.COMPILER_LATEST_ZIP
# 
#     def library_repos(self):
#         return StubConfig.LIBRARY_GIT_REPOS
# 
#     def compiler_flagfile(self):
#         return StubConfig.COMPILER_FLAGFILE
# 
#     def compiler_flagfile_for_debug(self):
#         return StubConfig.COMPILER_FLAGFILE_FOR_DEBUG
# 
#     def linter_flagfile(self):
#         return StubConfig.LINTER_FLAGFILE
# 
# class StubConfigOnStubProject(object):
#     def __init__(self):
#         pass
# 
#     def development_dir(self):
#         return StubConfigOnStubProject.DEVELOPMENT_DIR
# 
#     def debug_dir(self):
#         return StubConfigOnStubProject.DEBUG_DIR
# 
#     def production_dir(self):
#         return StubConfigOnStubProject.PRODUCTION_DIR
# 
#     def compiled_js_ext(self):
#         return StubConfigOnStubProject.COMPILED_JS_EXT
# 
#     def test_file_pattern(self):
#         return StubConfigOnStubProject.TEST_FILE_PATTERN
# 
#     def library_root(self):
#         return StubConfigOnStubProject.LIBRARRY_ROOT
# 
#     def closurebuilder(self):
#         return StubConfigOnStubProject.CLOSUREBUILDER
# 
#     def depswriter(self):
#         return StubConfigOnStubProject.DEPSWRITER
# 
#     def compiler_root(self):
#         return StubConfigOnStubProject.COMPILER_ROOT
# 
#     def base_js(self):
#         return StubConfigOnStubProject.BASE_JS
# 
#     def multitestrunner_css(self):
#         return StubConfigOnStubProject.MULTI_TEST_RUNNER_CSS
# 
#     def js_dev_dir(self):
#         return StubConfigOnStubProject.JS_DEV_DIR
# 
#     def deps_js(self):
#         return StubConfigOnStubProject.DEPS_JS
# 
#     def testrunner(self):
#         return StubConfigOnStubProject.TESTRUNNER
# 
#     def compiler(self):
#         return StubConfigOnStubProject.COMPILER
# 
#     def compilation_level(self):
#         return StubConfigOnStubProject.COMPILATION_LEVEL
# 
#     def compiler_zip(self):
#         return StubConfigOnStubProject.COMPILER_LATEST_ZIP
# 
#     def library_repos(self):
#         return StubConfigOnStubProject.LIBRARY_GIT_REPOS
# 
#     def compiler_flagfile(self):
#         return StubConfigOnStubProject.COMPILER_FLAGFILE
# 
#     def compiler_flagfile_for_debug(self):
#         return StubConfigOnStubProject.COMPILER_FLAGFILE_FOR_DEBUG
# 
#     def linter_flagfile(self):
#         return StubConfigOnStubProject.LINTER_FLAGFILE
# 
# Path: test/stub_environment.py
# class StubEnvironment(object):
#     def __init__(self):
#         self.cwd = None
#         self.tree = None
#         self.argument = None


# Path: test/commands/test_build.py
import unittest
import doctest
import os
import subprocess
import googkit.lib.strutil
import googkit.commands.build
from googkit.compat.unittest import mock
from test.stub_config import StubConfig, StubConfigOnStubProject
from test.stub_environment import StubEnvironment

        expected.compiler_arg('--flagfile', StubConfig.COMPILER_FLAGFILE)

        self.cmd.compiled_js_path = mock.MagicMock()
        self.cmd.compiled_js_path.side_effect = lambda _: 'dummy.JS'

        with mock.patch('os.path.exists', return_value=True):
            args = self.cmd.production_arguments('dummy.html', StubConfig.PROJECT_DIR)
        self.assertEqual(args, expected)


    def test_build_production(self):
        self.cmd.setup_files = mock.MagicMock()
        self.cmd.production_arguments = mock.MagicMock()
        self.cmd.production_arguments.return_value = ['ARG']

        MockPopen = mock.MagicMock()
        mock_popen = MockPopen.return_value
        # It simulates the command was succeeded
        mock_popen.returncode = 0

        with mock.patch('subprocess.Popen', new=MockPopen):
            self.cmd.build_production(StubConfig.PROJECT_DIR, False)

        self.cmd.setup_files.assert_called_once_with(StubConfig.PRODUCTION_DIR, False)
        MockPopen.assert_called_once_with(
            ['python', StubConfig.CLOSUREBUILDER, 'ARG'],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

    def test_build_debug(self):

        self.cmd.setup_files = mock.MagicMock()