# Path: gen_manifest/gen_manifest.py
# ALL_LANGS = ["python", "java", "csharp", "nodejs", "ruby", "php", "go"]
# BASEPATH_KEY = 'basepath'
# BASEPATH_DEFAULT = '.'
# BIN_KEY = 'bin'
# INVOCATION_KEY = 'invocation'
# def emit_manifest_v3(tags, sample_globs, flat):
# def create_factored_manifest_v3(tags, sample_globs):
# def create_flat_manifest_v3(tags, sample_globs):
# def emit_manifest_v2(tags, sample_globs, flat):
# def create_manifest_v2(tags, sample_globs):
# def path_sample_pairs_v2(sample_globs):
# def forbid_names(tags, *forbidden_names):
# def escape(text):
# def get_region_tag(sample_file_path):
# def glob_non_yaml(all_patterns):
# def dict_representer(dumper, data):
# def dump(manifest):
# def parse_files_and_tags(params: List[str]) -> (List[str], List[str]):
# def main(schema_version: str, output: str, flat: bool, files_and_tags: List[str]):
# class GenManifestError(Exception):
# class TagNameError(GenManifestError):
# class RegionTagError(GenManifestError):
# class NotRegularFileError(GenManifestError):
# class UnrecognizedLanguageError(GenManifestError):


from glob import glob
from click.testing import CliRunner
from collections import OrderedDict
from gen_manifest import gen_manifest
from textwrap import dedent
import unittest
import os
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.



_ABS_FILE = os.path.abspath(__file__)
_ABS_DIR = os.path.dirname(_ABS_FILE)

class TestGenManifest(unittest.TestCase):

  def test_glob_non_yaml(self):
    def basenames_of(files):
      return {os.path.basename(match) for match in files}

    gen_manifest_cwd = os.path.abspath(os.path.join(_ABS_DIR, '..', '..'))
    sample_relative_path = os.path.join('tests','testdata','gen_manifest')
    sample_path = os.path.abspath(os.path.join(gen_manifest_cwd, sample_relative_path))
    self.assertEquals({'readbook.py', 'getbook.py', 'some.random.yaml'},
                      basenames_of(
                          glob(os.path.join(sample_path, '**/*'),
                               recursive=True)))

    # ensure we exclude the *.yaml incldued in the naive globbing above
    self.assertEquals({'readbook.py', 'getbook.py'},
                      basenames_of(
                          gen_manifest.glob_non_yaml(
                              [os.path.join(sample_path, '**/*')])))

  def test_parse_files_and_tags(self):

# Path: gen_manifest/gen_manifest.py
# ALL_LANGS = ["python", "java", "csharp", "nodejs", "ruby", "php", "go"]
# BASEPATH_KEY = 'basepath'
# BASEPATH_DEFAULT = '.'
# BIN_KEY = 'bin'
# INVOCATION_KEY = 'invocation'
# def emit_manifest_v3(tags, sample_globs, flat):
# def create_factored_manifest_v3(tags, sample_globs):
# def create_flat_manifest_v3(tags, sample_globs):
# def emit_manifest_v2(tags, sample_globs, flat):
# def create_manifest_v2(tags, sample_globs):
# def path_sample_pairs_v2(sample_globs):
# def forbid_names(tags, *forbidden_names):
# def escape(text):
# def get_region_tag(sample_file_path):
# def glob_non_yaml(all_patterns):
# def dict_representer(dumper, data):
# def dump(manifest):
# def parse_files_and_tags(params: List[str]) -> (List[str], List[str]):
# def main(schema_version: str, output: str, flat: bool, files_and_tags: List[str]):
# class GenManifestError(Exception):
# class TagNameError(GenManifestError):
# class RegionTagError(GenManifestError):
# class NotRegularFileError(GenManifestError):
# class UnrecognizedLanguageError(GenManifestError):


# Path: tests/gen_manifest/gen_manifest_test.py
from glob import glob
from click.testing import CliRunner
from collections import OrderedDict
from gen_manifest import gen_manifest
from textwrap import dedent
import unittest
import os

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.



_ABS_FILE = os.path.abspath(__file__)
_ABS_DIR = os.path.dirname(_ABS_FILE)

class TestGenManifest(unittest.TestCase):

  def test_glob_non_yaml(self):
    def basenames_of(files):
      return {os.path.basename(match) for match in files}

    gen_manifest_cwd = os.path.abspath(os.path.join(_ABS_DIR, '..', '..'))
    sample_relative_path = os.path.join('tests','testdata','gen_manifest')
    sample_path = os.path.abspath(os.path.join(gen_manifest_cwd, sample_relative_path))
    self.assertEquals({'readbook.py', 'getbook.py', 'some.random.yaml'},
                      basenames_of(
                          glob(os.path.join(sample_path, '**/*'),
                               recursive=True)))

    # ensure we exclude the *.yaml incldued in the naive globbing above
    self.assertEquals({'readbook.py', 'getbook.py'},
                      basenames_of(
                          gen_manifest.glob_non_yaml(
                              [os.path.join(sample_path, '**/*')])))

  def test_parse_files_and_tags(self):

    files, tags = gen_manifest.parse_files_and_tags(['--principal=alice',