Example #1
0
 def test_content_restored(self):
     original_content = open(self.file1).read()
     with backup_file(self.file1):
         with open(self.file1, 'w') as f:
             f.write("more content")
         self.assertNotEqual(original_content, open(self.file1).read())
     self.assertEqual(original_content, open(self.file1).read())
Example #2
0
 def test_deletion(self):
     original_content = open(self.file1).read()
     with backup_file(self.file1):
         self.assertTrue(os.path.exists(self.file1))
         os.remove(self.file1)
         self.assertFalse(os.path.exists(self.file1))
     self.assertTrue(os.path.exists(self.file1))
     self.assertEqual(original_content, open(self.file1).read())
Example #3
0
    def test_collision_names(self):
        another_file = "{}.bak".format(self.file1)
        another_content = "another file with the expected name for backup"
        with open(another_file, "w") as f:
            f.write("another file with the expected name for backup")

        with backup_file(self.file1):
            self.assertTrue(True)

        self.assertTrue(os.path.exists(another_file))
        self.assertEqual(another_content, open(another_file).read())
Example #4
0
def conf(new_values, conan_conf=None):
    conan_conf = conan_conf or os.path.join(os.path.expanduser("~"), '.conan',
                                            'conan.conf')
    if not os.path.exists(conan_conf):
        raise RuntimeError(
            "Cannot find configuration file at '{}'".format(conan_conf))

    with backup_file(conan_conf):
        config = ConfigParser()
        config.optionxform = str
        config.read(conan_conf)
        for section, item, new_value in new_values:
            config[section][item] = new_value

        with open(conan_conf, 'w') as output_config:
            config.write(output_config)
        yield config  # TODO: Should return a ConanConf object

    pass
Example #5
0
 def run(self, *args, **kwargs):
     with backup_file(
             os.path.join(os.path.expanduser("~"), '.conan',
                          'registry.txt')):
         return super(TestRun, self).run(*args, **kwargs)
Example #6
0
 def test_invalid_file(self):
     with self.assertRaises(IOError):
         with backup_file("invented-file-name"):
             self.assertTrue(True)
Example #7
0
 def run(self, *args, **kwargs):
     # TODO: A lot better if we start from a synthetic conan.conf file
     self.conan_conf = os.path.join(os.path.expanduser("~"), '.conan', 'conan.conf')
     with backup_file(self.conan_conf):
         super(TestParserConanConf, self).run(*args, **kwargs)