#10 Consolidate modulemd file content tests
Merged 6 years ago by ncoghlan. Opened 6 years ago by ncoghlan.
modularity/ ncoghlan/fedmod avoid-repeated-test-modulemd-generation  into  master

file modified
+46 -40
@@ -3,66 +3,72 @@ 

  from fedmod.cli import ModtoolsCLI

  from fedmod.module_generator import ModuleGenerator

  

+ def _generate_modulemd(rpms):

+     cmd_input = list(['rpm2module'])

+     cmd_input.extend(rpms)

+     cli = ModtoolsCLI(cmd_input)

+     mg = ModuleGenerator(cli.pkgs)

+     mg.run()

+     if len(rpms) == 1:

+         output_fname = rpms[0] + '.yaml'

+     else:

+         output_fname = 'modulemd-output.yaml'

+     return mg, output_fname

+ 

  

  class TestSinglePackageInput(object):

  

      def setup(self):

-         self.input = 'grep'

-         # TODO: test this on modtools when it is packaged

-         cmd_input = list(['rpm2module'])

-         cmd_input.append(self.input)

-         cli = ModtoolsCLI(cmd_input)

-         mg = ModuleGenerator(cli.pkgs)

-         self.md = mg

-         mg.run()

+         self.input_rpms = input_rpms = ('grep',)

+         self.md, self.output_fname = _generate_modulemd(input_rpms)

  

      def teardown(self):

-         os.remove(self.input + '.yaml')

+         os.remove(self.output_fname)

+ 

+     def test_generated_modulemd_file(self):

+         # File exists with expected name

+         assert os.path.isfile(self.input_rpms[0] + '.yaml')

  

-     def test_description(self):

+         # Expected description for 'grep'

+         assert self.md.mmd.summary == "Pattern matching utilities"

          assert (self.md.mmd.description == 'The GNU versions of commonly used grep utilities. Grep searches through\n' +

                  'textual input for lines which contain a match to a specified pattern and then\n' +

                  'prints the matching lines. GNU\'s grep utilities include grep, egrep and fgrep.\n\n' +

                  'GNU grep is needed by many scripts, so it shall be installed on every system.')

  

-     def test_licences(self):

-         assert(len(self.md.mmd.module_licenses) == 1)

-         assert(sorted(self.md.mmd.module_licenses) == sorted(['MIT']))

-         assert(len(self.md.mmd.content_licenses) == 1)

-         assert(sorted(self.md.mmd.content_licenses) == sorted(['GPLv3+']))

- 

-     def test_summary(self):

-         assert(self.md.mmd.summary == "Pattern matching utilities")

+         # Expected licenses for 'grep'

+         assert len(self.md.mmd.module_licenses) == 1

+         assert sorted(self.md.mmd.module_licenses) == sorted(['MIT'])

+         assert len(self.md.mmd.content_licenses) == 1

+         assert sorted(self.md.mmd.content_licenses) == sorted(['GPLv3+'])

  

-     def test_api(self):

-         assert(len(self.md.mmd.api.rpms) == 1)

-         assert(sorted(self.md.mmd.api.rpms) == sorted([self.input]))

- 

-     def test_output(self):

-         assert(os.path.isfile(self.input + '.yaml'))

+         # Only given modules are listed in the public API

+         assert len(self.md.mmd.api.rpms) == 1

+         assert sorted(self.md.mmd.api.rpms) == sorted(self.input_rpms)

  

  

  class TestMultiplePackageInput(object):

  

      def setup(self):

-         self.input = ['grep','mariadb']

-         cmd_input = list(['rpm2module'])

-         cmd_input.extend(self.input)

-         cli = ModtoolsCLI(cmd_input)

-         mg = ModuleGenerator(cli.pkgs)

-         self.md = mg

-         mg.run()

+         self.input_rpms = input_rpms = ('grep', 'mariadb')

+         self.md, self.output_fname = _generate_modulemd(input_rpms)

  

      def teardown(self):

-         os.remove('modulemd-output.yaml')

+         os.remove(self.output_fname)

+ 

+     def test_generated_modulemd_file(self):

+         # File exists with expected name

+         assert os.path.isfile('modulemd-output.yaml')

  

-     def test_licences(self):

-         assert(len(self.md.mmd.module_licenses) == 1)

-         assert(sorted(self.md.mmd.module_licenses) == sorted(['MIT']))

+         # Can't generate descriptive metadata when given multiple RPMs

+         assert self.md.mmd.summary == ""

+         assert self.md.mmd.description == ""

  

-     def test_api(self):

-         assert(len(self.md.mmd.api.rpms) == len(self.input))

-         assert(sorted(self.md.mmd.api.rpms) == sorted(self.input))

+         # Expected licenses for 'grep'

+         assert len(self.md.mmd.module_licenses) == 1

+         assert sorted(self.md.mmd.module_licenses) == sorted(['MIT'])

+         assert len(self.md.mmd.content_licenses) == 0 # This doesn't seem right...

  

-     def test_output(self):

-         assert (os.path.isfile('modulemd-output.yaml'))

+         # Only given modules are listed in the public API

+         assert len(self.md.mmd.api.rpms) == len(self.input_rpms)

+         assert sorted(self.md.mmd.api.rpms) == sorted(self.input_rpms)

The tests currently only cover two input scenarios
(grep and grep+mariadb). To speed up the tests,
only run each file generation once, and then make
multiple assertions about it in a single consolidated
test case.

Pull-Request has been merged by ncoghlan

6 years ago

Combined with previous changes to the module generator itself, this brings the current test execution time below 5 seconds :)

Metadata