# Path: ethronsoft/gcspypi/package/package.py
# class Package(object):
# 
#     def __init__(self, name, version="", requirements=set([]), type=""):
#         self.name = name.replace("_", "-")
#         self.version = complete_version(version) if version else None
#         self.requirements = set([])
#         self.type = type
#         for r in requirements:
#             self.requirements.add(r.replace("_","-"))
# 
#     @staticmethod
#     def repo_name(pkg, filename):
#         if not pkg.version:
#             raise InvalidState("cannot formulate package repository-name for a package without version")
#         return "{name}/{version}/{filename}".format(
#             name=pkg.name,
#             version=pkg.version,
#             filename=os.path.split(filename)[1]
#         )
# 
#     @staticmethod
#     def from_text(text):
#         if ">" in text or "<" in text:
#             raise InvalidParameter("Cannot create a package with non deterministic version")
#         if "==" in text:
#             name, version = text.split("==")
#             return Package(name.strip(), version.strip())
#         else:
#             return Package(text)
# 
#     def __str__(self):
#         return self.full_name
# 
#     def __repr__(self): # pragma: no cover
#         return "<Package {}>".format(str(self))
# 
#     def __eq__(self, o):
#         if not o: return False
#         return (self.name, self.version, self.type) == (o.name, o.version, o.type)
# 
#     def __ne__(self, o):
#         return not self.__eq__(o)
# 
#     def __hash__(self):
#         return hash((self.name, str(self.version), self.type))
# 
#     @property
#     def full_name(self):
#         return self.name + ":" + self.version if self.version else self.name
# 
# Path: ethronsoft/gcspypi/exceptions/boundary_errors.py
# class InvalidParameter(Exception):
#     pass
# 
# Path: ethronsoft/gcspypi/exceptions/state_errors.py
# class InvalidState(Exception):
#     pass


from ethronsoft.gcspypi.package.package import Package
from ethronsoft.gcspypi.exceptions import InvalidParameter, InvalidState
import pytest
    p = Package("some", "1.0.0")
    assert p.full_name == "some:1.0.0"
    wrong = Package("some", "")
    assert Package.repo_name(p, "/some/filename.txt") == "some/1.0.0/filename.txt"
    with pytest.raises(InvalidState):
        Package.repo_name(wrong, "/some/filename.txt") 

def test_equality():
    p1 = Package("some", "1.0.0", type="A")
    p2 = Package("some", "1.0.0", type="A")
    p3 = Package("some", "1.0.0", type="B")
    p4 = Package("some", "", type="A")
    p5 = Package("other", "1.0.0", type="A")
    p6 = Package("other", "1.0.0", type="B")
    
    assert p1.full_name == str(p1)
    assert p1 == p2
    assert hash(p1) == hash(p2)
    assert p1 != p3
    assert hash(p1) != hash(p3) 
    assert p1 != p4
    assert p2 != p5
    assert p5 != p6


def test_from_text():
    with pytest.raises(InvalidParameter):
        Package.from_text("some>1.0.0")
    with pytest.raises(InvalidParameter):
        Package.from_text("some<1.0.0")

# Path: ethronsoft/gcspypi/package/package.py
# class Package(object):
# 
#     def __init__(self, name, version="", requirements=set([]), type=""):
#         self.name = name.replace("_", "-")
#         self.version = complete_version(version) if version else None
#         self.requirements = set([])
#         self.type = type
#         for r in requirements:
#             self.requirements.add(r.replace("_","-"))
# 
#     @staticmethod
#     def repo_name(pkg, filename):
#         if not pkg.version:
#             raise InvalidState("cannot formulate package repository-name for a package without version")
#         return "{name}/{version}/{filename}".format(
#             name=pkg.name,
#             version=pkg.version,
#             filename=os.path.split(filename)[1]
#         )
# 
#     @staticmethod
#     def from_text(text):
#         if ">" in text or "<" in text:
#             raise InvalidParameter("Cannot create a package with non deterministic version")
#         if "==" in text:
#             name, version = text.split("==")
#             return Package(name.strip(), version.strip())
#         else:
#             return Package(text)
# 
#     def __str__(self):
#         return self.full_name
# 
#     def __repr__(self): # pragma: no cover
#         return "<Package {}>".format(str(self))
# 
#     def __eq__(self, o):
#         if not o: return False
#         return (self.name, self.version, self.type) == (o.name, o.version, o.type)
# 
#     def __ne__(self, o):
#         return not self.__eq__(o)
# 
#     def __hash__(self):
#         return hash((self.name, str(self.version), self.type))
# 
#     @property
#     def full_name(self):
#         return self.name + ":" + self.version if self.version else self.name
# 
# Path: ethronsoft/gcspypi/exceptions/boundary_errors.py
# class InvalidParameter(Exception):
#     pass
# 
# Path: ethronsoft/gcspypi/exceptions/state_errors.py
# class InvalidState(Exception):
#     pass


# Path: test/package_test.py
from ethronsoft.gcspypi.package.package import Package
from ethronsoft.gcspypi.exceptions import InvalidParameter, InvalidState
import pytest

    p = Package("some", "1.0.0")
    assert p.full_name == "some:1.0.0"
    wrong = Package("some", "")
    assert Package.repo_name(p, "/some/filename.txt") == "some/1.0.0/filename.txt"
    with pytest.raises(InvalidState):
        Package.repo_name(wrong, "/some/filename.txt") 

def test_equality():
    p1 = Package("some", "1.0.0", type="A")
    p2 = Package("some", "1.0.0", type="A")
    p3 = Package("some", "1.0.0", type="B")
    p4 = Package("some", "", type="A")
    p5 = Package("other", "1.0.0", type="A")
    p6 = Package("other", "1.0.0", type="B")
    
    assert p1.full_name == str(p1)
    assert p1 == p2
    assert hash(p1) == hash(p2)
    assert p1 != p3
    assert hash(p1) != hash(p3) 
    assert p1 != p4
    assert p2 != p5
    assert p5 != p6


def test_from_text():
    with pytest.raises(InvalidParameter):
        Package.from_text("some>1.0.0")
    with pytest.raises(InvalidParameter):
        Package.from_text("some<1.0.0")

    with pytest.raises(InvalidParameter):