Source

hgfilemerge / tests / test_main.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import unittest
import filecmp

from hgfilemerge import HgFileMerge

class TestYmlConfigParser(unittest.TestCase):
    def setUp(self):
        self.merger = HgFileMerge()
        self.merger.configure_from_file('tests/testfiles/conf.yml')
        
    def test_simple_yml_base_path(self):
        self.assertEqual(self.merger.base_path,
                         'tests/testfiles/test_yml_config_parser/')
    
    def test_simple_yml_merge_groups(self):
        self.assertEqual(self.merger.merge_groups,
                         {'merged_most_popular.css': ['1.css', '2.css',],
                          'merged_site.css': ['3.css',]})

class TestSimple(unittest.TestCase):
    def setUp(self):
        import codecs
        
        self.merger = HgFileMerge()
        self.merger.configure_from_file('tests/testfiles/conf.yml')
        
        self.f = codecs.open('tests/testfiles/test_yml_config_parser/1_2_merged.css', 'r', 'utf-8')
        
    def tearDown(self):
        self.f.close()
    
    def test_merge_groups(self):
        self.assertEqual(self.merger.get_merge_groups(),
                         ['merged_most_popular.css',
                          'merged_site.css'])
    
    def test_merge(self):
        self.assertEqual(self.merger.get_merged('merged_most_popular.css'),
                         self.f.readlines())
    
    def test_save(self):
        os.remove('tests/testfiles/test_yml_config_parser/1.css')
        os.remove('tests/testfiles/test_yml_config_parser/2.css')
        # os.remove('tests/testfiles/test_yml_config_parser/3.css')
        self.merger.save('merged_most_popular.css')
        self.assertEqual(filecmp.cmp('tests/testfiles/test_yml_config_parser/merged_most_popular.css',
                                     'tests/testfiles/test_yml_config_parser/1_2_merged.css',
                                     shallow=True),
                         True)