def test_generation_v3_flat_forbidden_tag(self):
        self.maxDiff = None

        sample_path = os.path.abspath(
            os.path.join(_ABS_DIR, '..', 'testdata', 'gen_manifest'))
        for forbidden_name in ['path', 'sample']:
            with self.assertRaises(gen_manifest.TagNameError):
                manifest_string = gen_manifest.emit_manifest_v3(
                    tags=[(forbidden_name, 'foo')],
                    sample_globs=[
                        os.path.join(sample_path, 'readbook.py'),
                        os.path.join(sample_path, 'getbook.py')
                    ],
                    flat=True)
    def test_generation_v3_flat(self):
        self.maxDiff = None
        BIN = '/my/bin/'
        INVOCATION = 'call this way'
        CHDIR = '@/this/working/path/'
        ENV = 'python'

        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))
        manifest_string = gen_manifest.emit_manifest_v3(
            tags=[
                ('env', ENV),
                ('bin', BIN),
                ('invocation', INVOCATION),
                ('chdir', CHDIR),
                # ('basepath', 'should not be forbidden when flat')
            ],
            sample_globs=[
                os.path.join(sample_relative_path, 'readbook.py'),
                os.path.join(sample_relative_path, 'getbook.py')
            ],
            flat=True)

        expected_string = """type: manifest/samples
schema_version: 3
samples:
- bin: {bin}
  chdir: '{chdir}'
  env: {env}
  invocation: {invocation}
  path: ./{sample_relative_path}/readbook.py
  sample: readbook_sample
- bin: {bin}
  chdir: '{chdir}'
  env: {env}
  invocation: {invocation}
  path: ./{sample_relative_path}/getbook.py
  sample: getbook_sample
""".format(env=ENV,
           bin=BIN,
           invocation=INVOCATION,
           chdir=CHDIR,
           sample_relative_path=sample_relative_path)
        self.assertEqual(expected_string, manifest_string)
    def test_generation_v3_factored_basepath(self):
        self.maxDiff = None
        BIN = '/my/bin/'
        INVOCATION = 'call this way'
        CHDIR = '@/this/working/path/'
        ENV = 'python'
        BASEPATH = 'some/dir/path'

        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))
        manifest_string = gen_manifest.emit_manifest_v3(
            tags=[('env', ENV), ('bin', BIN), ('invocation', INVOCATION),
                  ('chdir', CHDIR), ('basepath', BASEPATH)],
            sample_globs=[
                os.path.join(sample_relative_path, 'readbook.py'),
                os.path.join(sample_relative_path, 'getbook.py')
            ],
            flat=False)

        expected_string = """type: manifest/samples
schema_version: 3
base: &common
  env: '{env}'
  bin: '{bin}'
  invocation: '{invocation}'
  chdir: '{chdir}'
  basepath: '{basepath}'
samples:
- <<: *common
  path: '{{basepath}}/{sample_relative_path}/readbook.py'
  sample: 'readbook_sample'
- <<: *common
  path: '{{basepath}}/{sample_relative_path}/getbook.py'
  sample: 'getbook_sample'
""".format(env=ENV,
           bin=BIN,
           invocation=INVOCATION,
           chdir=CHDIR,
           sample_relative_path=sample_relative_path,
           cwd=gen_manifest_cwd,
           basepath=BASEPATH)
        self.assertEqual(expected_string, manifest_string)
Exemple #4
0
    def test_generation_v3_flat(self):
        self.maxDiff = None
        BIN = '/my/bin/'
        INVOCATION = 'call this way'
        CHDIR = '@/this/working/path/'
        ENVIRONMENT = 'python'

        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))
        manifest_string = gen_manifest.emit_manifest_v3(
            tags=[
                ('environment', ENVIRONMENT),
                ('bin', BIN),
                ('invocation', INVOCATION),
                ('chdir', CHDIR),
            ],
            sample_globs=[
                os.path.join(sample_relative_path, 'readbook.py'),
                os.path.join(sample_relative_path, 'getbook.py')
            ],
            flat=True)

        expected_string = dedent(f"""\
      type: manifest/samples
      schema_version: 3
      samples:
      - path: './{sample_relative_path}/getbook.py'
        sample: 'getbook_sample'
        environment: '{ENVIRONMENT}'
        bin: '{BIN}'
        invocation: '{INVOCATION}'
        chdir: '{CHDIR}'
      - path: './{sample_relative_path}/readbook.py'
        sample: 'readbook_sample'
        environment: '{ENVIRONMENT}'
        bin: '{BIN}'
        invocation: '{INVOCATION}'
        chdir: '{CHDIR}'
      """)
        self.assertEqual(expected_string, manifest_string)
Exemple #5
0
    def test_generation_v3_factored_basepath(self):
        self.maxDiff = None
        BIN = '/my/bin/exe --flag'
        INVOCATION = 'call this way'
        CHDIR = '@/this/working/path/'
        ENVIRONMENT = 'python'
        BASEPATH = 'some/dir/path'

        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))
        manifest_string = gen_manifest.emit_manifest_v3(
            tags=[('environment', ENVIRONMENT), ('bin', BIN),
                  ('invocation', INVOCATION), ('chdir', CHDIR),
                  ('basepath', BASEPATH)],
            sample_globs=[
                os.path.join(sample_relative_path, 'readbook.py'),
                os.path.join(sample_relative_path, 'getbook.py')
            ],
            flat=False)

        expected_string = dedent(f"""\
      type: manifest/samples
      schema_version: 3
      base: &common
        environment: '{ENVIRONMENT}'
        bin: '{BIN}'
        invocation: '{INVOCATION}'
        chdir: '{CHDIR}'
        basepath: '{BASEPATH}'
      samples:
      - <<: *common
        path: '{{basepath}}/{sample_relative_path}/getbook.py'
        sample: 'getbook_sample'
      - <<: *common
        path: '{{basepath}}/{sample_relative_path}/readbook.py'
        sample: 'readbook_sample'
      """)
        self.assertEqual(expected_string, manifest_string)