# Path: webpack/conf.py
# class Conf(conf.Conf):
#     # Environment configuration
#     OUTPUT_ROOT = None
#     STATIC_URL = None
#     OUTPUT_DIR = 'webpack_assets'
#     CONFIG_DIRS = None
#     CONTEXT = None
# 
#     # Build server
#     BUILD_URL = 'http://127.0.0.1:9009/build'
# 
#     # Watching
#     WATCH = False
#     AGGREGATE_TIMEOUT = 200
#     POLL = None
#     HMR = False
# 
#     # Caching
#     CACHE = True
#     CACHE_DIR = None
# 
#     # Manifest
#     MANIFEST = None
#     USE_MANIFEST = False
#     MANIFEST_PATH = None
#     MANIFEST_SETTINGS = {
#         # Force the compiler to connect to the build server
#         'USE_MANIFEST': False,
#         # Ensure that the server does not add a hmr runtime
#         'HMR': False,
#     }
# 
#     def get_path_to_output_dir(self):
#         return os.path.join(self.OUTPUT_ROOT, self.OUTPUT_DIR)
# 
#     def get_public_path(self):
#         static_url = self.STATIC_URL
#         if static_url and static_url.endswith('/'):
#             static_url = static_url[:-1]
# 
#         return '/'.join([static_url, self.OUTPUT_DIR])
# 
# Path: webpack/manifest.py
# def generate_manifest(entries, settings=None):
#     manifest = {}
# 
#     if isinstance(entries, dict):
#         for config_file, contexts in six.iteritems(entries):
#             contexts = contexts or (None,)
#             for context in contexts:
#                 _add_entry_to_manifest(manifest, settings, config_file, context)
#     else:
#         for config_file in entries:
#             _add_entry_to_manifest(manifest, settings, config_file)
# 
#     return manifest
# 
# def generate_key(config_file, context=None):
#     if not context:
#         return config_file
# 
#     hashable_context = json.dumps(context).encode('utf-8')
#     context_hash = hashlib.md5(hashable_context).hexdigest()
#     return '{}__{}'.format(config_file, context_hash)
# 
# def write_manifest(path, manifest):
#     content = json.dumps(manifest, indent=4, sort_keys=True)
# 
#     with open(path, 'w') as manifest_file:
#         manifest_file.write(content)
# 
# def read_manifest(path):
#     if not os.path.exists(path):
#         raise ManifestDoesNotExist('Cannot find webpack manifest file at {}'.format(path))
# 
#     with open(path, 'r') as manifest_file:
#         content = manifest_file.read()
# 
#     return json.loads(content)
# 
# def populate_manifest_file():
#     if not conf.settings.MANIFEST:
#         raise ImproperlyConfigured('webpack\'s MANIFEST setting has not been defined')
# 
#     if not conf.settings.MANIFEST_PATH:
#         raise ImproperlyConfigured('webpack\'s MANIFEST_PATH setting has not been defined')
# 
#     manifest = generate_manifest(
#         conf.settings.MANIFEST,
#         conf.settings.MANIFEST_SETTINGS,
#     )
# 
#     write_manifest(conf.settings.MANIFEST_PATH, manifest)
# 
# Path: webpack/compiler.py
# def webpack(config_file, context=None, settings=None, manifest=manifest_reader, compiler=build_server):
#     use_manifest = conf.settings.USE_MANIFEST
# 
#     # Allow the USE_MANIFEST setting to be overridden when populating the manifest
#     if settings:
#         use_manifest = settings.get('USE_MANIFEST', use_manifest)
# 
#     if use_manifest:
#         return manifest.read(config_file, context)
# 
#     return compiler.build(
#         config_file=config_file,
#         extra_context=context,
#         setting_overrides=settings,
#     )
# 
# Path: tests/settings.py
# class ConfigFiles(object):
#     BASIC_CONFIG = os.path.join('basic', 'webpack.config.js')
#     LIBRARY_CONFIG = os.path.join('library', 'webpack.config.js')
#     MULTIPLE_BUNDLES_CONFIG = os.path.join('multiple_bundles', 'webpack.config.js')
#     MULTIPLE_ENTRY_CONFIG = os.path.join('multiple_entry', 'webpack.config.js')
#     CACHED_CONFIG = os.path.join('cached', 'webpack.config.js')
# 
# OUTPUT_ROOT = os.path.join(BASE_DIR, 'generated_assets')
# 
# WEBPACK = {
#     'OUTPUT_ROOT': OUTPUT_ROOT,
#     'STATIC_URL': STATIC_URL,
#     'CONTEXT': {
#         'default_context': 'test'
#     },
#     'CONFIG_DIRS': (
#         BASE_DIR,
#         BUNDLES,
#     ),
#     # While webpack-build's cache will check for asset existence,
#     # watching compilers do not, so we need to ensure that the cache
#     # is cleared between runs
#     'CACHE_DIR': os.path.join(OUTPUT_ROOT, 'cache_dir'),
# }
# 
# Path: tests/utils.py
# def clean_output_root():
#     # Clean out any files generated from previous test runs
#     if os.path.exists(settings.OUTPUT_ROOT):
#         shutil.rmtree(settings.OUTPUT_ROOT)


import unittest
import os
import json
import mock
import hashlib
from webpack.conf import Conf
from webpack.manifest import generate_manifest, generate_key, write_manifest, read_manifest, populate_manifest_file
from webpack.compiler import webpack
from .settings import ConfigFiles, OUTPUT_ROOT, WEBPACK
from .utils import clean_output_root


class TestManifest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        clean_output_root()

    @classmethod
    def tearDownClass(cls):

# Path: webpack/conf.py
# class Conf(conf.Conf):
#     # Environment configuration
#     OUTPUT_ROOT = None
#     STATIC_URL = None
#     OUTPUT_DIR = 'webpack_assets'
#     CONFIG_DIRS = None
#     CONTEXT = None
# 
#     # Build server
#     BUILD_URL = 'http://127.0.0.1:9009/build'
# 
#     # Watching
#     WATCH = False
#     AGGREGATE_TIMEOUT = 200
#     POLL = None
#     HMR = False
# 
#     # Caching
#     CACHE = True
#     CACHE_DIR = None
# 
#     # Manifest
#     MANIFEST = None
#     USE_MANIFEST = False
#     MANIFEST_PATH = None
#     MANIFEST_SETTINGS = {
#         # Force the compiler to connect to the build server
#         'USE_MANIFEST': False,
#         # Ensure that the server does not add a hmr runtime
#         'HMR': False,
#     }
# 
#     def get_path_to_output_dir(self):
#         return os.path.join(self.OUTPUT_ROOT, self.OUTPUT_DIR)
# 
#     def get_public_path(self):
#         static_url = self.STATIC_URL
#         if static_url and static_url.endswith('/'):
#             static_url = static_url[:-1]
# 
#         return '/'.join([static_url, self.OUTPUT_DIR])
# 
# Path: webpack/manifest.py
# def generate_manifest(entries, settings=None):
#     manifest = {}
# 
#     if isinstance(entries, dict):
#         for config_file, contexts in six.iteritems(entries):
#             contexts = contexts or (None,)
#             for context in contexts:
#                 _add_entry_to_manifest(manifest, settings, config_file, context)
#     else:
#         for config_file in entries:
#             _add_entry_to_manifest(manifest, settings, config_file)
# 
#     return manifest
# 
# def generate_key(config_file, context=None):
#     if not context:
#         return config_file
# 
#     hashable_context = json.dumps(context).encode('utf-8')
#     context_hash = hashlib.md5(hashable_context).hexdigest()
#     return '{}__{}'.format(config_file, context_hash)
# 
# def write_manifest(path, manifest):
#     content = json.dumps(manifest, indent=4, sort_keys=True)
# 
#     with open(path, 'w') as manifest_file:
#         manifest_file.write(content)
# 
# def read_manifest(path):
#     if not os.path.exists(path):
#         raise ManifestDoesNotExist('Cannot find webpack manifest file at {}'.format(path))
# 
#     with open(path, 'r') as manifest_file:
#         content = manifest_file.read()
# 
#     return json.loads(content)
# 
# def populate_manifest_file():
#     if not conf.settings.MANIFEST:
#         raise ImproperlyConfigured('webpack\'s MANIFEST setting has not been defined')
# 
#     if not conf.settings.MANIFEST_PATH:
#         raise ImproperlyConfigured('webpack\'s MANIFEST_PATH setting has not been defined')
# 
#     manifest = generate_manifest(
#         conf.settings.MANIFEST,
#         conf.settings.MANIFEST_SETTINGS,
#     )
# 
#     write_manifest(conf.settings.MANIFEST_PATH, manifest)
# 
# Path: webpack/compiler.py
# def webpack(config_file, context=None, settings=None, manifest=manifest_reader, compiler=build_server):
#     use_manifest = conf.settings.USE_MANIFEST
# 
#     # Allow the USE_MANIFEST setting to be overridden when populating the manifest
#     if settings:
#         use_manifest = settings.get('USE_MANIFEST', use_manifest)
# 
#     if use_manifest:
#         return manifest.read(config_file, context)
# 
#     return compiler.build(
#         config_file=config_file,
#         extra_context=context,
#         setting_overrides=settings,
#     )
# 
# Path: tests/settings.py
# class ConfigFiles(object):
#     BASIC_CONFIG = os.path.join('basic', 'webpack.config.js')
#     LIBRARY_CONFIG = os.path.join('library', 'webpack.config.js')
#     MULTIPLE_BUNDLES_CONFIG = os.path.join('multiple_bundles', 'webpack.config.js')
#     MULTIPLE_ENTRY_CONFIG = os.path.join('multiple_entry', 'webpack.config.js')
#     CACHED_CONFIG = os.path.join('cached', 'webpack.config.js')
# 
# OUTPUT_ROOT = os.path.join(BASE_DIR, 'generated_assets')
# 
# WEBPACK = {
#     'OUTPUT_ROOT': OUTPUT_ROOT,
#     'STATIC_URL': STATIC_URL,
#     'CONTEXT': {
#         'default_context': 'test'
#     },
#     'CONFIG_DIRS': (
#         BASE_DIR,
#         BUNDLES,
#     ),
#     # While webpack-build's cache will check for asset existence,
#     # watching compilers do not, so we need to ensure that the cache
#     # is cleared between runs
#     'CACHE_DIR': os.path.join(OUTPUT_ROOT, 'cache_dir'),
# }
# 
# Path: tests/utils.py
# def clean_output_root():
#     # Clean out any files generated from previous test runs
#     if os.path.exists(settings.OUTPUT_ROOT):
#         shutil.rmtree(settings.OUTPUT_ROOT)


# Path: tests/test_manifest.py
import unittest
import os
import json
import mock
import hashlib
from webpack.conf import Conf
from webpack.manifest import generate_manifest, generate_key, write_manifest, read_manifest, populate_manifest_file
from webpack.compiler import webpack
from .settings import ConfigFiles, OUTPUT_ROOT, WEBPACK
from .utils import clean_output_root



class TestManifest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        clean_output_root()

    @classmethod
    def tearDownClass(cls):

        clean_output_root()