
import os
import tempfile

from handroll.site import Site
from handroll.tests import TestCase


class TestSite(TestCase):

    def test_finds_valid_site_root_from_templates(self):
        original = os.getcwd()
        valid_site = tempfile.mkdtemp()
        open(os.path.join(valid_site, 'template.html'), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_finds_valid_site_root_from_conf(self):
        original = os.getcwd()
        valid_site = tempfile.mkdtemp()
        open(os.path.join(valid_site, Site.CONFIG), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_site_has_absolute_path(self):
        original = os.getcwd()
        tempdir = tempfile.mkdtemp()
        site_path = os.path.join(tempdir, 'site')
        os.mkdir(site_path)
        os.chdir(tempdir)

        site = Site('site')

        self.assertEqual(site_path, site.path)
        os.chdir(original)


import os
import tempfile

from handroll.site import Site
from handroll.tests import TestCase


class TestSite(TestCase):

    def test_finds_valid_site_root_from_templates(self):
        original = os.getcwd()
        valid_site = os.path.realpath(tempfile.mkdtemp())
        open(os.path.join(valid_site, 'template.html'), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_finds_valid_site_root_from_conf(self):
        original = os.getcwd()
        valid_site = os.path.realpath(tempfile.mkdtemp())
        open(os.path.join(valid_site, Site.CONFIG), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_site_has_absolute_path(self):
        original = os.getcwd()
        tempdir = os.path.realpath(tempfile.mkdtemp())
        site_path = os.path.join(tempdir, 'site')
        os.mkdir(site_path)
        os.chdir(tempdir)

        site = Site('site')

        self.assertEqual(site_path, site.path)
        os.chdir(original)

Use a real path when testing sites.
Use a real path when testing sites.

Mac OS X returns link paths when calling `mkdtemp`. Calling realpath
allows the site path comparison to be consistent across platforms.

  
  import os
  import tempfile
  
  from handroll.site import Site
  from handroll.tests import TestCase
  
  
  class TestSite(TestCase):
  
      def test_finds_valid_site_root_from_templates(self):
          original = os.getcwd()
-         valid_site = tempfile.mkdtemp()
+         valid_site = os.path.realpath(tempfile.mkdtemp())
          open(os.path.join(valid_site, 'template.html'), 'w').close()
          os.chdir(valid_site)
  
          site = Site()
  
          self.assertEqual(valid_site, site.path)
          os.chdir(original)
  
      def test_finds_valid_site_root_from_conf(self):
          original = os.getcwd()
-         valid_site = tempfile.mkdtemp()
+         valid_site = os.path.realpath(tempfile.mkdtemp())
          open(os.path.join(valid_site, Site.CONFIG), 'w').close()
          os.chdir(valid_site)
  
          site = Site()
  
          self.assertEqual(valid_site, site.path)
          os.chdir(original)
  
      def test_site_has_absolute_path(self):
          original = os.getcwd()
-         tempdir = tempfile.mkdtemp()
+         tempdir = os.path.realpath(tempfile.mkdtemp())
          site_path = os.path.join(tempdir, 'site')
          os.mkdir(site_path)
          os.chdir(tempdir)
  
          site = Site('site')
  
          self.assertEqual(site_path, site.path)
          os.chdir(original)
  
Use a real path when testing sites.
## Code Before:

import os
import tempfile

from handroll.site import Site
from handroll.tests import TestCase


class TestSite(TestCase):

    def test_finds_valid_site_root_from_templates(self):
        original = os.getcwd()
        valid_site = tempfile.mkdtemp()
        open(os.path.join(valid_site, 'template.html'), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_finds_valid_site_root_from_conf(self):
        original = os.getcwd()
        valid_site = tempfile.mkdtemp()
        open(os.path.join(valid_site, Site.CONFIG), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_site_has_absolute_path(self):
        original = os.getcwd()
        tempdir = tempfile.mkdtemp()
        site_path = os.path.join(tempdir, 'site')
        os.mkdir(site_path)
        os.chdir(tempdir)

        site = Site('site')

        self.assertEqual(site_path, site.path)
        os.chdir(original)

## Instruction:
Use a real path when testing sites.
## Code After:

import os
import tempfile

from handroll.site import Site
from handroll.tests import TestCase


class TestSite(TestCase):

    def test_finds_valid_site_root_from_templates(self):
        original = os.getcwd()
        valid_site = os.path.realpath(tempfile.mkdtemp())
        open(os.path.join(valid_site, 'template.html'), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_finds_valid_site_root_from_conf(self):
        original = os.getcwd()
        valid_site = os.path.realpath(tempfile.mkdtemp())
        open(os.path.join(valid_site, Site.CONFIG), 'w').close()
        os.chdir(valid_site)

        site = Site()

        self.assertEqual(valid_site, site.path)
        os.chdir(original)

    def test_site_has_absolute_path(self):
        original = os.getcwd()
        tempdir = os.path.realpath(tempfile.mkdtemp())
        site_path = os.path.join(tempdir, 'site')
        os.mkdir(site_path)
        os.chdir(tempdir)

        site = Site('site')

        self.assertEqual(site_path, site.path)
        os.chdir(original)
