def setUp(self):
     self.load_dir()
     self.load_sass(name='test1', content=SASS1)
     self.compass = Compass({
         'sass_dir': self.sass_dir,
         'css_dir': self.css_dir,
         'boring': True,
         'quiet': True,
         'output_style': 'compressed',
     })
class TestCompass(TempDirEnvironmentMixin, TestCase):

    def setUp(self):
        self.load_dir()
        self.load_sass(name='test1', content=SASS1)
        self.compass = Compass({
            'sass_dir': self.sass_dir,
            'css_dir': self.css_dir,
            'boring': True,
            'quiet': True,
            'output_style': 'compressed',
        })

    def test_compile(self):
        output = self.compass.compile()
        self.assertEquals(self.list_css(), ['test1.css'])
        with open(os.path.join(self.css_dir, 'test1.css')) as css:
            self.assertEquals(css.read(), "body{color:red}body a{color:blue}\n")

        self.load_sass(name='test2', content=SASS2)
        self.assertRaises(CompassError, self.compass.compile)

    def test_compile_file(self):
        self.load_sass(name='test2', content=SASS3)
        self.compass.compile_file('test2.sass')
        self.assertEquals(self.list_css(), ['test2.css'])
        self.assertRaises(CompassError, self.compass.compile_file, 'fake')

    def test_compile_file_with_deep(self):
        os.mkdir(os.path.join(self.sass_dir, 'dir1'))
        os.mkdir(os.path.join(self.sass_dir, 'dir1', 'dir2'))
        into_dir = os.path.join('dir1', 'dir2', 'deep')
        self.load_sass(name=into_dir, content=SASS1)
        self.compass.compile_file('deep.sass')
        self.assertEquals(os.listdir(
            os.path.join(self.css_dir, 'dir1/dir2')), ['deep.css'])

    def test_compile_file_with_two_equals(self):
        """
        /sass_dir/dir/into1/deep.sass
        /sass_dir/dir/into2/deep.sass
        """
        parent_dir = os.path.join(self.sass_dir, 'dir')
        os.mkdir(parent_dir)
        os.mkdir(os.path.join(parent_dir, 'into1'))
        os.mkdir(os.path.join(parent_dir, 'into2'))
        self.load_sass(
            name=os.path.join('dir', 'into1', 'deep'), content=SASS1)
        self.load_sass(
            name=os.path.join('dir', 'into2', 'deep'), content=SASS1)
        self.compass.compile_file('dir/into1/deep.sass')
        self.assertEquals(os.listdir(
            os.path.join(self.css_dir, 'dir/into1')), ['deep.css'])
        self.assertEquals(os.listdir(
            os.path.join(self.css_dir, 'dir')), ['into1'])