def test_multiple_lines_separated_in_project(self):
        global_content = textwrap.dedent("""\
            foo<2;python_version=='2.7'
            foo>1;python_version!='2.7'
            """)
        project_content = textwrap.dedent("""\
            foo<1.8;python_version=='2.7'
            # mumbo gumbo
            foo>0.9;python_version!='2.7'
            """)
        global_reqs = update._parse_reqs(global_content)
        project_reqs = list(update._content_to_reqs(project_content))
        actions = update._sync_requirements_file(
            global_reqs, project_reqs, 'f', False, False, 'f', False)
        self.assertEqual(update.File('f', textwrap.dedent("""\
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
foo<2;python_version=='2.7'
foo>1;python_version!='2.7'
# mumbo gumbo
""")), actions[1])
        self.assertEqual(update.StdOut(
            "    foo<1.8;python_version=='2.7'  ->   "
            "foo<2;python_version=='2.7'\n"), actions[4])
        self.assertEqual(update.StdOut(
            "    foo>0.9;python_version!='2.7'  ->   "
            "foo>1;python_version!='2.7'\n"), actions[5])
        self.assertThat(actions, matchers.HasLength(6))
    def test_extras_no_change(self):
        global_content = textwrap.dedent(u"""\
            foo<2;python_version=='2.7' # BSD
            foo>1;python_version!='2.7'
            freddy
            """)
        setup_cfg = textwrap.dedent(u"""\
            [metadata]
            name = openstack.requirements

            [extras]
            test =
              foo<2:python_version=='2.7' # BSD
              foo>1:python_version!='2.7'
            opt =
              freddy
            """)
        project = {}
        project['root'] = '/dev/null'
        project['requirements'] = {}
        project['setup.cfg'] = setup_cfg
        global_reqs = update._parse_reqs(global_content)
        actions = update._copy_requires(
            u'', False, False, project, global_reqs, False)
        self.assertEqual([
            update.Verbose('Syncing extra [opt]'),
            update.Verbose('Syncing extra [test]'),
            update.File('setup.cfg', setup_cfg)], actions)
 def test_multiple_lines_separated_in_project(self):
     global_content = textwrap.dedent("""\
         foo<2;python_version=='2.7'
         foo>1;python_version!='2.7'
         """)
     project_content = textwrap.dedent("""\
         foo<1.8;python_version=='2.7'
         # mumbo gumbo
         foo>0.9;python_version!='2.7'
         """)
     global_reqs = update._parse_reqs(global_content)
     project_reqs = list(update._content_to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(
         global_reqs, project_reqs, 'f', False, False, False)
     self.assertEqual(update.Requirements([
         update.Requirement('foo', '<2', "python_version=='2.7'", ''),
         update.Requirement('foo', '>1', "python_version!='2.7'", ''),
         update.Requirement('', '', '', "# mumbo gumbo")]),
         reqs)
     self.assertEqual(update.StdOut(
         "    foo<1.8;python_version=='2.7'  ->   "
         "foo<2;python_version=='2.7'\n"), actions[2])
     self.assertEqual(update.StdOut(
         "    foo>0.9;python_version!='2.7'  ->   "
         "foo>1;python_version!='2.7'\n"), actions[3])
     self.assertThat(actions, matchers.HasLength(4))
 def test_multiple_lines_nochange(self):
     global_content = textwrap.dedent("""\
         foo<2;python_version=='2.7'
         foo>1;python_version!='2.7'
         """)
     project_content = textwrap.dedent("""\
         foo<2;python_version=='2.7'
         foo>1;python_version!='2.7'
         """)
     global_reqs = update._parse_reqs(global_content)
     project_reqs = list(update._content_to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(
         global_reqs, project_reqs, 'f', False, False, False)
     self.assertEqual(update.Requirements([
         update.Requirement('foo', '<2', "python_version=='2.7'", ''),
         update.Requirement('foo', '>1', "python_version!='2.7'", '')]),
         reqs)
     self.assertThat(actions, matchers.HasLength(0))
 def test_single_global_multiple_in_project(self):
     global_content = textwrap.dedent("""\
         foo>1
         """)
     project_content = textwrap.dedent("""\
         foo<2;python_version=='2.7'
         foo>1;python_version!='2.7'
         """)
     global_reqs = update._parse_reqs(global_content)
     project_reqs = list(update._content_to_reqs(project_content))
     actions, reqs = update._sync_requirements_file(
         global_reqs, project_reqs, 'f', False, False, False)
     self.assertEqual(update.Requirements([
         update.Requirement('foo', '>1', "", '')]),
         reqs)
     self.assertEqual(update.StdOut(
         "    foo<2;python_version=='2.7'    ->   foo>1\n"), actions[2])
     self.assertEqual(update.StdOut(
         "    foo>1;python_version!='2.7'    ->   \n"), actions[3])
     self.assertThat(actions, matchers.HasLength(4))
Exemple #6
0
    def setUp(self):
        super(GlobalRequirements, self).setUp()
        self.root = self.useFixture(fixtures.TempDir()).path
        self.req_file = os.path.join(self.root, "global-requirements.txt")
        shutil.copy(
            "openstack_requirements/tests/files/gr-base.txt", self.req_file)


# Static data for unit testing.
def make_project(fixture):
    with fixture:
        return update._read_project(fixture.root)


global_reqs = update._parse_reqs(
    open("openstack_requirements/tests/files/gr-base.txt", "rt").read())
pbr_project = make_project(pbr_fixture)
project_project = make_project(project_fixture)
bad_project = make_project(bad_project_fixture)
oslo_project = make_project(oslo_fixture)


def project_file(
        fail, project, action_filename, suffix=None, softupdate=None,
        non_std_reqs=False):
    actions = update._process_project(
        project, global_reqs, suffix, softupdate, None,
        non_std_reqs)
    for action in actions:
        if type(action) is update.File:
            if action.filename == action_filename: