def load(self, filename, create_if_missing=True):
        filename = Path(filename)
        if not filename.exists() and create_if_missing:
            self.load_pip_requirements()
            with filename.open("w") as f:
                f.write(yaml.dump(self.serialized, default_flow_style=False,
                                  encoding=None))
            self.filename = filename
            return self.save(filename)
        with filename.open() as f:
            for group, requirements in yaml.load(f.read()).items():
                for requirement in requirements:
                    self[group].add(Requirement.coerce(requirement))
        self.filename = filename
def test_bad_urls():
    values = [
        'foo',
        'http://',
        'http://example',
        'http://example.',
        'http://.com',
        'http://invalid-.com',
        'http://-invalid.com',
        'http://inv-.alid-.com',
        'http://inv-.-alid.com',
        'foo bar baz',
        u'foo \u2713',
        'http://@foo:bar@example.com',
        'http://:bar@example.com',
        'http://bar:bar:bar@example.com',
    ]

    for value in values:
        yield check_bad_url_raises, value