def test_add_project(self): proj = Project(FakeEnv(), 'project') self.sln[Phony('phony')] = proj self.assertTrue(Phony('phony') in self.sln) self.assertTrue(Phony('foobar') not in self.sln) self.assertTrue(File(Path('phony')) not in self.sln) self.assertIs(self.sln[Phony('phony')], proj) self.assertEqual(list(iter(self.sln)), [proj])
def test_set_default(self): foo_proj = Project(FakeEnv(), 'foo_proj') self.sln[Phony('foo')] = foo_proj bar_proj = Project(FakeEnv(), 'bar_proj') self.sln[Phony('bar')] = bar_proj self.assertEqual(list(iter(self.sln)), [foo_proj, bar_proj]) self.sln.set_default(Phony('bar')) self.assertEqual(list(iter(self.sln)), [bar_proj, foo_proj]) self.sln.set_default(Phony('nonexist')) self.assertEqual(list(iter(self.sln)), [bar_proj, foo_proj])
def test_dependencies(self): class MockOutput: class MockCreator: def __init__(self, output): self.public_output = output def __init__(self, output=None): self.creator = self.MockCreator(output) if output else None output = Phony('dep') proj = Project(FakeEnv(), 'project') self.sln[output] = proj self.assertEqual( self.sln.dependencies([MockOutput(), MockOutput([output])]), [proj]) with self.assertRaises(RuntimeError): self.sln.dependencies([MockOutput([Phony('wrong')])])
def test_write(self): proj = Project(FakeEnv(), 'project') self.sln[Phony('phony')] = proj out = StringIO() self.sln.write(out) assertRegex( self, out.getvalue(), r'(?m)^Project\("{[A-Z0-9-]+}"\) = "project", ' + r'"project.project\.proj", "{[A-Z0-9-]+}"$' )
def test_write(self): class MockDependency: uuid_str = '{00000000-0000-0000-0000-000000000001}' foo_proj = Project(FakeEnv(), 'foo_proj') self.sln[Phony('foo')] = foo_proj bar_proj = Project(FakeEnv(), 'bar_proj', dependencies=[foo_proj]) self.sln[Phony('bar')] = bar_proj out = StringIO() self.sln.write(out) guid_ex = '{[A-Z0-9-]+}' self.assertRegex( out.getvalue(), (r'(?m)^Project\("{0}"\) = "{1}", "{1}.{1}\.proj", "{0}"\n' r'EndProject\n' r'Project\("{0}"\) = "{2}", "{2}.{2}\.proj", "{0}"\n' r'\tProjectSection\(ProjectDependencies\) = postProject\n' r'\t\t{0} = {0}\n' r'\tEndProjectSection\n' r'EndProject$').format(guid_ex, 'foo_proj', 'bar_proj'))
def test_invalid(self): phony = Phony('name') self.assertRaises(TypeError, self.context['install'], phony) exe = Executable(Path('/path/to/exe', Root.absolute), None) self.assertRaises(ValueError, self.context['install'], exe)